- Online Community Forums » Programming Questions » Views in allegro 5

This thread is locked; no one can reply to it. rss feed Print
Views in allegro 5
Member #12,521
January 2011

I read the allegro 5 API but found no information about views. You have a room 3500x900 but the screen is 640x480. How can i make the screen follow the player ? And how can i divide room into views as i mentioned above

Dario ff
Member #10,065
August 2008

That really doesn't concern Allegro 5 since it's a bit higher level, it's up to you to do a "scrolling" camera.

If your background is simply going to be one big bitmap, Allegro can draw specific regions of a bitmap using al_draw_bitmap_region. For any other map engines, there are plenty of tutorials around.

TranslatorHack 2010, a human translation chain in
My games: [GiftCraft] - [Blocky Rhythm[SH2011]] - [Elven Revolution] - [Dune Smasher!]

Member #12,521
January 2011

which functions should i use for scrolling camera ?

Member #1,134
March 2001

I usually keep an x and y coordinate for a camera, personally. Set it to be offset from the player's position by a certain amount at all times. Then, during the render, I offset everything I draw by that x and y. Simplest way in my opinion.

Allegro has no "function" for that. It's something you take care of. Or write a function for yourself. :)

Software Development == Church Development
Step 1. Build it.
Step 2. Pray.

Todd Cope
Member #998
November 2000

xantier said:

which functions should i use for scrolling camera ?

You can use transformations to "scroll the camera" if you don't want to offset your rendering manually. For example:

ALLEGRO_TRANSFORM camera_transform;

al_translate_transform(&camera_transform, -camera_x, -camera_y);

Member #11,410
October 2009

int camx;
int camy;

for each bitmap
drawBitmap(bitmapPosX - camx, bitmapPosY - camy, bitmap);

The idea is that if object is at 15 and camera is at 15, then by subtracting 15 it will be at 0 therefore in the center.

Go to: