Views in allegro 5
xantier

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

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.

xantier

which functions should i use for scrolling camera ?

23yrold3yrold

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. :)

Todd Cope
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_identity_transform(&camera_transform);
al_translate_transform(&camera_transform, -camera_x, -camera_y);
al_use_transform(&camera_transform);
render_everything();

jmasterx

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.

Thread #606211. Printed from Allegro.cc