The SDL forums have moved to discourse.libsdl.org.
This is just a read-only archive of the previous forums, to keep old links working.


SDL Forum Index
SDL
Simple Directmedia Layer Forums
Camera Tutorial
Tabris


Joined: 19 Nov 2009
Posts: 10
Hi

I have been looking around for a good C (not c++, i dont wanna use objects yet Mad) 2d scrolling camera tutorial...but i havent got any luck.

So...does anyone know of any good tutorial or care to explain to me how to make a scrolling cam for a 2d platformer?

Thanks in advance =)
Camera Tutorial
David Olofson
Guest

On Wednesday 25 November 2009, at 01.59.34, "Tabris"
wrote:
Quote:
Hi

I have been looking around for a good C (not c++, i dont wanna use objects
yet Mad) 2d scrolling camera tutorial...but i havent got any luck.

So...does anyone know of any good tutorial or care to explain to me how to
make a scrolling cam for a 2d platformer?

Thanks in advance =)

Are you going to use OpenGL or the SDL 2D API? (Not that it differs much
beyond the technical details, as long as we're *really* talking 2D as opposed
to "3D with 2D style camera".)

Here are some basic examples that covers both:
http://olofson.net/examples.html

The parallax examples are SDL 2D only, whereas the smoothscroll example
supports SDL 2D as well as OpenGL, selectable by command line switch.

(Smoothscroll is actually intended to demonstrate sub-pixel accurate
positioning for ultra-smooth scrolling, but that's really just a tweak to
"basic" OpenGL scrolling of tiled backgrounds.)


--
//David Olofson - Developer, Artist, Open Source Advocate

.--- Games, examples, libraries, scripting, sound, music, graphics ---.
| http://olofson.net http://kobodeluxe.com http://audiality.org |
| http://eel.olofson.net http://zeespace.net http://reologica.se |
'---------------------------------------------------------------------'
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Tabris


Joined: 19 Nov 2009
Posts: 10
Hey thanks! i will look into it tomorrow and see if i can understand it =)
Camera Tutorial
Jonny D


Joined: 12 Sep 2009
Posts: 932
If you're just unsure of how to get started with a 2d camera, then try this:

typedef struct Camera
{
float x, y;
} Camera;

Create a camera somewhere reasonable:
Camera cam;

In your game loop, update it each logic frame:
cam.x = player.x - screen->w/2;
cam.y = player.y - screen->h/2;

Then draw the scrolling stuff (this is just a wrapper for SDL_BlitSurface):
blitSurface(player.image, screen, player.x - cam.x, player.y - cam.y);

Everything that you adjust with the camera position will be scrolling.

Good luck,
Jonny D


On Tue, Nov 24, 2009 at 11:31 PM, Tabris wrote:
Quote:
Hey thanks! i will look into it tomorrow and see if i can understand it =)
_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org


_______________________________________________
SDL mailing list

http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org