- Online Community Forums » Programming Questions » How to make a bitmap blink?

This thread is locked; no one can reply to it. rss feed Print
How to make a bitmap blink?
Ivan Klevnikov
Member #16,571
October 2016

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:

1case ALLEGRO_KEY_X: 2 { 3 4 al_draw_bitmap(start, 30, 100, NULL); 5 al_flip_display(); 6 al_rest(2.0); 7 al_destroy_bitmap(start); 8 al_flip_display(); 9 al_rest(2.0); 10 done = true; 11 break; 12 }

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!

Member #907
January 2001

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.

Member #13,038
July 2011

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.


Edgar Reynaldo
Member #8,592
May 2007

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);

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;

Go to: