Transformations Tutorial
V T

Hello all,

I have been working on and off (mostly off due to time restraints) on a game for a long time. I've recently ported it to Allegro 5 from Allegro 4. I'm trying to take as full advantage of Allegro 5's features as I can. One thing I do not seem to understand as well however are transformations.

I've found the Coding Made Easy tutorial on youtube which shows how to use transformations to do camera scrolling. I've been able to implement it somewhat, but I guess my problem is I don't quite understand why it works. Well that, and I have trouble getting it to work while also transformations to scale the graphics to fit the windows. I'm thinking if I understood it better maybe I could get it to work the way I want.

Anyway, long story short, Ive looked around and do not see any tutorials that give a really in depth explanation of how transformations work. Is there one around that I may just be missing?

Thanks in advance

jmasterx

How it works is by multiplying transformation matricies together to obtain the final point http://en.wikipedia.org/wiki/Affine_transformation#Augmented_matrix

The way it works for scrolling is, imagine the world starts at 0,0,. I draw all my objects relative to 0,0 the world coordinates.

The transformations basically act like a camera and can allow you to look at say 200-800 of the world or something.

Elias

This also has a short explanation:
http://docs.liballeg.org/transformations.html

V T

So the problem that I am having right now is getting my camera to work when scaling the screen. I originally designed my game with smaller graphics that were scaled up to fix the screen. I have attempted to do that here using transformations, and the scaling works, but the camera scrolls too slow,and the character moves off the screen. Here is some of the code I am using:

#SelectExpand
1void draw() 2{ 3 al_identity_transform(&camera); 4 5 al_translate_transform(&camera,-cameraPosition[0],-cameraPosition[1]); 6 al_scale_transform(&camera,scaleX,scaleY); 7 al_use_transform(&camera); 8 9 //MapDrawBG(0,0,0,0,al_get_bitmap_width(level),al_get_bitmap_height(level)); 10 //MapDrawFG(0,0,0,0,al_get_bitmap_width(level),al_get_bitmap_height(level),0); 11 //display_player_health(); 12 13 al_draw_bitmap(pinkx,0,0,0); 14 15 16 al_identity_transform(&camera); 17 al_scale_transform(&camera,scaleX,scaleY); 18 al_use_transform(&camera); 19 20 21 Player.draw_actor(level,player); 22 23 24 25 26 al_hold_bitmap_drawing(false); 27 28 al_set_target_bitmap(al_get_backbuffer(display)); 29 30 al_flip_display(); 31} 32void cameraUpdate(float *cameraPosition, float x, float y, int width, int height) 33{ 34 cameraPosition[0] = -((SCREEN_W / 2) / scaleX) + (x + width / 2); 35 cameraPosition[1] = -(SCREEN_H / 2) + (y + height / 2); 36 37 if (cameraPosition[0] < 0) 38 cameraPosition[0] = 0; 39 if (cameraPosition[1] < 0) 40 cameraPosition[1] = 0; 41}

Note that SCREEN_W is set to 800 and I'm not scrolling up and down. (I need to remove the y camera updating as its irrelevant. I'm using mappy but have the drawing function commented out as it doesn't seem to work with transforms either. (or I'm doing it wrong). Anyone have any suggestions? Let me know if you need more info.

Thomas Fjellstrom

Unless mappy also sets transforms, transforms should be totally invisible to it.

As for the scroll speed, you'll want to scale that too i think.

V T

How would I go about scaling or slowing down the scroll speed of the camera? I actually realized it doesn't work properly even when its not scaled. The player still moves faster when the camera is being scrolled then he does when the camera is stationary.

Thread #614580. Printed from Allegro.cc