2D Game Dev – Part 4.1: Timing Our Game Loop

This post is a portion of Part 4 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.

In this video we look at the preliminaries of timing our game loop in Allegro 5.

Source code can be found here.

Notice that the source code is slightly different from the video? Here is why.

Posted in 2D Game Dev, Allegro, C++, Code, Game Dev, Part 4, Tutorial
10 Comments » for 2D Game Dev – Part 4.1: Timing Our Game Loop
  1. Mr.Mike says:

    Awesome tutorials! Pretty nice job!

    I have one doubt: is it efficient to declare the ‘ev’ variable inside the game loop? I mean, will the program be reserving a piece o memory for that variable every time the loop is triggered?

    Thanks!

    • Mike says:

      It doesn’t cause a noticeable impact on performance, though it would probably be more efficient to be declared only once. Though, by declaring it every cycle, there is certain to be no residual data left over from a previous cycle.

  2. Ben Arnold says:

    When you tell the program to wait for an event, it not only picks up the timer, it picks up the mouse move events and such as well. I noticed that I had 60 fps when not moving the mouse, but as I moved the mouse around the screen my fps skyrocketed. To fix this is there a way to check what type the event is? So the loop would only execute if ev.type == timer or something like that?

  3. nocrej says:

    Great job Mike! Your tutorials are very helpeful. Keep ‘em coming! ^^

  4. nocrej says:

    Great job Mike! Your tutorials are very helpful. Keep ‘em coming! ^^

  5. lars says:

    mike,

    i’ve got a problem: i can’t get 60 fps, my computer can’t reach higher then 30 give or take, any solutions? or should i make my games 30 fps?

    • Mike says:

      You can’t get 60 FPS without your game doing anything else? Or is is processing something? 60 FPS should be an easy target to hit until your code does any heavy lifting

      • lars says:

        thnx for the quick reply, i cant get to 60 fps while the window is open, when i pres the small flat bar beside the red X for close (so the screen isn’t open but still active) i can hit 3000-4000 fps so with this code only 60 fps. but with or without the 60 fps limit i can only reach around 30 fps when the window is open. i use a notebook, so it isn’t exactly designed for games but i thougt it should be able to reacht 60 fps…

  6. GigaRoid says:

    Thanks! Your tutorials have really helped me! But for some reason, when I put this code in, it goes really slow. It’s the exact code, but it runs approximately 10 fps at most. I have it set at 50 (common NES fps). What am I doing wrong?

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>

  • Skrilles better watch out. New dubstep group laying it down: http://t.co/tMzmjs0F 1 hour ago
  • Everyday I'm kerfuffle-ing. 22 hours ago
  • Who's got two thumbs and finished his research paper? This guy! #ayyyyyyy #fonz 1 day ago
  • App Idea- tag cloud favorite book and allow user to assemble sentences. Algorithmically assign tones. User can hear favorite lines from book 1 day ago
  • I just wrote 2 sentences of this research paper and I feel exhausted. 1 day ago