How can I draw multiple bitmaps to the backbuffer at the same time?
Anatta

Hello everyone,

I've just finished the Allegro 5 API Tutorials. I decide to write a simple snake game to strengthen what I've learnt.

But I hit a big wall just after I get start I tried to draw 2 bitmaps to the backbuffer but after flipping the display, just only 1 bitmap (head) showed up. I went back to the tutorials but cannot find the way, then do a lot of searches but helpless.

Full code:

Edgar Reynaldo

You're mixing drawing and logic. Learn to break that habit and separate the two and you'll be much better off.

Anatta said:

15 if ((headx + heads == foodx && heady == foody) || 16 (heady + heads == foody && headx == foodx) || 17 (headx - foods == foodx && heady == foody) || 18 (heady - foods == foody && headx == foodx)) { 19 ++score; 20 foodx = disx(gen); 21 foody = disx(gen); 22 /// you're drawing inside logic
23 al_draw_bitmap(food, foodx, foody, 0);
24 } 25 redraw = true; 26 } 27/// DRAWING GOES HERE 28 if (redraw && al_is_event_queue_empty(evque)) { 29 al_flip_display(); 30 redraw = false; 31 }

Anatta

Hi! Thank you for the advice. I've just fixed it.

But still haven't figured out how to draw 2 bitmaps at same time to backbuffer

1// after this function I only see head bitmap on the black screen. 2void setup_first_frame() { 3 al_set_target_bitmap(head); 4 al_clear_to_color(al_map_rgb(255, 255, 255)); 5 6 al_set_target_bitmap(food); 7 al_clear_to_color(al_map_rgb(0, 255, 0)); 8 9 al_set_target_backbuffer(disp); 10 al_clear_to_color(al_map_rgb(0, 0, 0)); 11 12 al_flip_display(); 13}

Edgar Reynaldo

Well, is 'food_eaten' true? For how long? Currently it should disappear right away, and only show up when you eat it. Consider your logic.

Anatta

Thank you I've figured out.