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.
- Part 4.0 – A Look at Timing
- Part 4.1 – Timing Our Game Loop
- Part 4.2 – Putting the Timing Together
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.
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!
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.
is there another way to make sure there’s no ‘residual’ data left over? And what are the possible implications of it
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?
Nevermind sorry haha you explain it in the next video.
Great job Mike! Your tutorials are very helpeful. Keep ’em coming! ^^
Great job Mike! Your tutorials are very helpful. Keep ’em coming! ^^
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?
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
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…
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?
I’m getting an “R6210 -abort ()” error that i can’t seem to fix…
This error only happens when i put in the text rendering (i also got the same error when I ran your exact code).
Hi, Running this code I noticed that whether you put the ev declaration inside or outside the loop, the memory the program is taking gradually increases. (in a matter of several kb s per every 3-4 seconds). Why is that?
The code is an infinite loop… Although evident, didn’t like it !
once again tnx for this awesome tutorials (Y)
one ques, what if i want to see how much FPS my computer can produce? how would i do it, i mean how can i measure time in allegro?
i have a ques, how come one ALLEGRO_EVENT variable “ev” handles two types of events at the same time? i mean timer event is firing off in every 1/60th second and if i keep pressing a keyBoard button the ALLEGRO_EVENT_KEY_CHAR event is fired or if i move mouse ALLEGRO_EVENT_MOUSE_AXES event is firing. how come this one event handles more than one event?
will be really greatfull for you ans
Should we destroy the timer and event_queue at the end?
Oh, we did, nevermind.