This post is a portion of Part 6 in my on going series about 2D Game Development using the Allegro 5 library. These posts are in course order. You can see all of the posts in this course by clicking the “2D Game Development” button at the top of this site.
- 6.0 – Bitmaps
- 6.1 – Creating Bitmaps
- 6.2 – Loading Premade Bitmaps
- 6.3 – Rotating, Scaling, Tinting Bitmaps
The final video of Part 6, in this video, we look at three functions that allow us to modify bitmaps in game.
Rotating source code can be found here.
Scaling source code can be found here.
Tinting source code can be found here.

Since you released this part on rotating im trying to figure out how to implement mouse look feature in my code using al_draw_rotated_bitmap and al_fixatan2. Got no much luck so far. first issue i got is when im moving mouse to edge angles of display it keeps rotating my object. Second, i cant figure how to do positive calculation on bottom side using:
float playerAngle = al_fixatan2(mouse_x * pos_y – pos_x * pos_y, mouse_x * pos_x + mouse_y * pos_y) % (2*ALLEGRO_PI); // Im using divide instead of modulus so it can build solution.
I know its my lack of knowing math and programming, but im actually Food Science Technician IRL who just loves games
If anyone would like to look into code i wrote let me know and i’ll link it up.
Can you email me your full source code? I think that will help me help you.
Mailed you with source code. Also i made today question here: http://gamedev.stackexchange.com/questions/17864/allegro-5-mouse-look
Im really going to learn this hard way like everything.
Im happy to say that i solved this on very strange and unprofessional way.
angRadians = atan2(double(mouse_y) – double(pos_y), double(mouse_x) – double(pos_x));
playerAngle = angRadians * 0.995929659;
First of, i used math.h because allegro fixed math made me verbally curse compiler that i use. Second, 0.995929659 is random number that is close to (3 / PI) and it makes no sense but works.
Glad to hear it. Sorry I haven’t gotten to your email yet.
Hey, I’m making a space shooter game like the one on the site, but I’m adding in the ability for the ship to rotate using the ‘A’ and ‘D’ keys. In addition, I’ve also switched the movement of the ship over to the mouse.
At this point, I’m trying to get the bullets to fire from the current position that the ship is facing. Is there some type of mathematical process or ALLEGRO function that I can use to determine the location of the ship’s front once it has been rotated? If I can figure that out, I should be able to make the bullets always shoot from the front.
Thanks.
I do not believe there is an Allegro function, but what you are talking about is angular calculations (trigonometry). Basically, you need to take a portion of your velocity and split it between the x plane and the y plane. I cover the formula to do this in my gravity demo (Part 8 I think – Sprites). Basically, if you know the angle, in radians, and the velocity, you can use sin and cos to calculate the percentage of x and y movement.
Hey do you think you can hep me with this code?
http://codepad.org/5S3UZ4wc
Its supposed to be able to have the user draw a path and then draw the bitmap along that path but for some reason it isnt drawing the bitmap at all – or the animation.
Mike, please could you help me?
I would like to start making applications for my iPhone. In C + + I have more experience and I would like to use them. Please write me an e-mail @ marek.buday@pobox.sk. Thank you.