I am trying to create a 'press start' textbox (out of a .png bitmap) so that it blinks when the 'x' key is pressed, just before the game inits. I have been trying with this code:
I can create the bitmap in a blank screen, but it's impossible to destroy it, at least this way. Any help will be appreciated!
al_destroy_bitmap() frees the image in memory, you don't want to do that.
Try al_draw_rectangle(), to paint over the place where you drew the image.
This looks to be Allegro 5 which I'm not familiar with but from a flow stand point, one idea might be to make a second copy of your bitmap but at a much darker color. I.E. bright red and an almost black red. Then you could loop through the bit maps. Draw the bright, wait, draw dark. It would give a flicker or blinking affect with out losing the X altogether. Just an idea.
Ace
Just use a bool variable to determine the blink state of your button.
bool blink_on = true;
In your drawing code, draw based on the state of the blinker.
if (redraw) { al_clear_to_color(al_map_rgb(0,0,0));/// clear screen if (blink_on) { al_draw_bitmap(blinker , 0 , 0 , 0); } al_flip_display(); }
In your logic code, set the state of the blinker and redraw.
al_wait_for_event(queue , &ev); if (ev.type == ALLEGRO_EVENT_KEY_DOWN && ev.keyboard.keycode == ALLEGRO_KEY_X) { blink_on = false; redraw = true; } else if (ev.type == ALLEGRO_EVENT_KEY_UP && ev.keyboard.keycode == ALLEGRO_KEY_X) { blink_on = true; redraw = true; }