Camera Tutorial

Hi

I have been looking around for a good C (not c++, i dont wanna use objects yet :x) 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.)On Wednesday 25 November 2009, at 01.59.34, “Tabris” wrote:

Hi

I have been looking around for a good C (not c++, i dont wanna use objects
yet :x) 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 =)


//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 |
’---------------------------------------------------------------------’

Hey thanks! i will look into it tomorrow and see if i can understand it =)

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 DOn Tue, Nov 24, 2009 at 11:31 PM, Tabris wrote:

Hey thanks! i will look into it tomorrow and see if i can understand it =)


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org