2D Game Dev – Part 6.3: Rotating, Scaling, and Tinting Bitmaps

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.

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.

Posted in 2D Game Dev, Allegro, C++, Code, Game Dev, Part 6, Tutorial
9 Comments » for 2D Game Dev – Part 6.3: Rotating, Scaling, and Tinting Bitmaps
  1. Marko Lazic says:

    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.

  2. Marko Lazic says:

    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.

  3. Shannon says:

    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.

    • Mike says:

      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.

  4. Jasper Lu says:

    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.

  5. Marek Buday says:

    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.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

  • Well, #diablo3 servers are down... why do I need servers to play single player again? 11 minutes ago
  • Installing D3. By my powers combined! 1 hour ago
  • My calendar just beeped with "Lunch thing, bring chips". No location or desc. I obviously don't care about future me that much. 1 day ago
  • DIABLO 3!!!!!!!!!!!! I call to you! 1 day ago
  • First night of consequence free gaming since January. 2 days ago