When ever an event happens my images flicker except the background and the images that are primitives. I feel like I've had this problem before, but I'm not checking mouse events in a random place only if an axes event happens. I think it could be Buttons[i].IsMouseOver(Event.mouse.x, Event.mouse.y);. Would putting that in parameters produce weird things? I still don't think that would cause it because if it was a weird value over would just stay false and it would draw the up state of the button. Heres some snippets of the code
if(Event.type == ALLEGRO_EVENT_MOUSE_AXES) { for(int i = 0; i < (int)Buttons.size(); i++) { Buttons[i].IsMouseOver(Event.mouse.x, Event.mouse.y); }
if(Event.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN) { if(Buttons[SEARCH].IsMouseOver() == true) { //search }
the code below is part of a class thats separate to the program that I use for other programs too.
Let's see your redraw block when you draw your screen. It should only flicker if you are drawing something, showing it, and then draw something else and show it.
Do you mean this?
It's a little odd that you draw once for every event that you receive, although that would just cause lag as the drawing caught up with the mouse events. My only guess is that they flicker because you are behind in your drawing.
Try processing all events in the queue at once, and then if you have received one or more timer events, then draw.
I Changed it to this:
It seems it has reduced the number of flickers but it hasn't completely gotten rid of it.
I don't understand why it is flickering at all. The hover state of your buttons should not be changing back and forth rapidly, and that is the only thing that would cause your buttons to flicker.
What specifically is flickering, and between what two states?
Are you altering your 'Over' (hover) variable anywhere else except inside IsMouseOver(int,int)?
Well its not just the buttons that are flickering. When I mean flicker all the images disappear then reappear type of thing. But the over states couldn't be changed because there private. Could it be becuase the images are transparent? I made them in a separate program then loaded them in but there 50% transparent.
Post the code for Program.DrawUI(). It has nothing to do with being transparent. You must be rapidly changing states somehow, because there shouldn't be any flickering at all with a double buffered or page flipping drawing setup like Allegro provides.
I'm not drawing that many images. I've got a tile based game that draws over 1000 images and it has no problems.
The number of images that you draw is not the problem. It's how you're drawing the images. Something must be changing state back and forth, because that's the only thing that explains why images are being drawn on one frame and not on another.
It almost sounds like you're drawing directly to the screen, but I don't think that is even possible with Allegro 5.
Edit
Do any of the draw functions that you call in there call al_flip_display at all? If you're flipping the display more than once that could explain it.
Your right. I found an extra al_flip_display some where else in the code. After removing it all the flickering is gone.
Well, easy enough to make that mistake with A5 now I guess. Glad it's working now.