Timing and Bitmap Troubles
oobtim

sigh:'(

Been fiddling with my timers and main loop with regards to the timers and now have a loop which boils down to:

#SelectExpand
1while(!doExit) 2 { 3 //test for an event 4 bool get_event = al_wait_for_event_until(event_queue, &ev, &timeout); 5 6 //trigger a redraw or update 7 if(ev.type == ALLEGRO_EVENT_TIMER) 8 { 9 if(ev.timer.source == animTimer) 10 { 11 redraw = true; 12 } 13 else if(ev.timer.source == updateTimer) 14 { 15 update = true; 16 } 17 }else if(ev.type == ALLEGRO_EVENT_DISPLAY_CLOSE) { 18 break; 19 }else if(ev.type == ALLEGRO_EVENT_KEY_DOWN) 20 { 21 switch(ev.keyboard.keycode) { 22 case ALLEGRO_KEY_UP: 23 key[KEY_UP] = true; 24 break; 25 case ALLEGRO_KEY_DOWN: 26 key[KEY_DOWN] = true; 27 break; 28 case ALLEGRO_KEY_LEFT: 29 key[KEY_LEFT] = true; 30 break; 31 case ALLEGRO_KEY_RIGHT: 32 key[KEY_RIGHT] = true; 33 break; 34 case ALLEGRO_KEY_1: 35 player.playerSpeed += 0.1; //purely for testing 36 break; 37 case ALLEGRO_KEY_2: 38 player.playerSpeed -= 0.1; //purely for testing 39 break; 40 } 41 42 }else if(ev.type == ALLEGRO_EVENT_KEY_UP) 43 { 44 //test if a key has been released 45 switch(ev.keyboard.keycode) { 46 case ALLEGRO_KEY_UP: 47 key[KEY_UP] = false; 48 break; 49 50 case ALLEGRO_KEY_DOWN: 51 key[KEY_DOWN] = false; 52 break; 53 54 case ALLEGRO_KEY_LEFT: 55 key[KEY_LEFT] = false; 56 break; 57 58 case ALLEGRO_KEY_RIGHT: 59 key[KEY_RIGHT] = false; 60 break; 61 62 case ALLEGRO_KEY_ESCAPE: 63 doExit = true; 64 break; 65 } 66 } 67 68 //game logic 69 if(al_is_event_queue_empty(event_queue) && update){ 70 player.update(key); //tells the player what key has been pressed 71 72 //will they hit something if they move using this key? 73 if(playerBGCollision(player)){ 74 player.hasCollided(); //if so make them stand still (i.e. velocity == 0) 75 } 76 77 player.move(); //update position variables 78 update = false; 79 } 80 81 //drawing 82 if(al_is_event_queue_empty(event_queue) && redraw) { 83 84 al_clear_to_color(al_map_rgb(0,0,0)); //clear 85 MapDrawBG(plotMapx,plotMapy,0,0,SWIDTH,SHEIGHT); 86 player.plot(plotMapx, plotMapy); 87 MapDrawFG(plotMapx,plotMapy,0,0,SWIDTH,SHEIGHT,0); 88 89 al_flip_display(); 90 91 redraw = false; 92 } 93 94 } 95 al_destroy_display(display); 96 al_destroy_event_queue(event_queue); 97 return 0; 98};

From reading forums this was said to be the recommended way of carrying out the game loop (if you haven't noticed it is also based on the Allegro 5 tutorials). But for some reason there is a lag in the timing (speeds up and down), not big, but noticeable. Plus the screen flickers slightly as it scrolls.

I thought that this would be down to loading memory bitmaps rather than video bitmaps. But they are only a few 100kB! I loaded the bitmaps for the player sprite AFTER I created the display anyway to make them video but to no avail. I checked the flags of the bitmaps and they came out with a flag that I couldn't identify.

So...

  • Is there something wrong with my loop?

  • Why would my bitmaps say they have a flag of int value 1056 when I check? What type of bitmaps are they?

???

l j

Flags are stored bitwise
You must use something along these lines:

if (myFlags & FLAG_SOME_FLAG)
{
    // Flag is enabled
}

oobtim

Thank you, that sorts out whether I have video/memory bitmaps :D

Anything wrong with my loop though, as the glitch still remains?:-/

Is there something wrong with the way the updates and redraws are called? Updates and redraws are done 60 times a second and I have a separate timer for each.

EDIT

Sorted it :D Needed to use interpolation to get things running smoothly. That'll teach me to code after a few beers hic :-[

Thread #610349. Printed from Allegro.cc