Hi to all.
I am new to the forum and i'm trying to make my very first game with Allegro 5.
As it is new i can't find so much examples on the internet but with the help of the wiki i made something.
This "simple" program works like a charm exept for the fact that the scrolling of the choices in the menu is very slow. Another problem is that if i draw a filled circle at line 141, when i start the program the whole menu goes away and i have to go up and down with the keyboard 3-4 times and the menu comes back again.
Can you help me with the debugging?
Thanks in advance.
As for your program being slow I suggest you move the addon initialization code (like primitives and font addons) and put it after display creation. That should help.
As a clarification of the previous comment, it's not so much that you should move the initialisation code after creating the display, but you should load bitmaps and fonts after creating the display. Otherwise the bitmaps will be created as 'memory' bitmaps, which are always drawn with relatively slow software routines, instead of 'video' bitmaps, which can take advantage of hardware rendering.
Your structure is like this (psuedocode) :
while (!quit) { wait_for_event(); if (is_timer_event() && redraw) { Redraw(); redraw = false; } // logic if (stuff_changes) {redraw = true;} }
The problem with it is that redraw may be set to true by your logic, but it has to wait until the next event fires to perform the Redraw(). You won't have to wait very long because of the timer events, but it's still a little funky.
A better layout would be :
while (!quit) { while (1) { wait_for_event(); if (stuff_changes) {redraw = true;} if (is_timer_event()) {update_logic();redraw = true;} if (!events_in_queue) {break;} } if (redraw) { Redraw(); redraw = false; } }