0

The red bars a cross the top flickers. I can make them out of the loop but not in the loop.

#include <allegro.h>
void init();
void deinit();
int main() {
    init();
 
int length = 20;
int x= 900;
int y= 600;
int c;
    //while (!key[KEY_ESC]) {
         c = makecol(0, 0, 0);
        rectfill (screen, 0, 0, 900, 400, c); 
        c = makecol(0, 200, 0);
        rectfill (screen, 0, 0, 900, 400, c);// curb
   for (int i =0; i=10; i++){
       int bar=0;
       c = makecol(200, 0, 0);
        rectfill (screen, bar, 0, x+80, 40, c);
        c = makecol(0, 0, 0);
        rectfill (screen, bar+80, 0, x+100, 40, c);
        bar+=100;
        }
  
    deinit();
    return 0;
}
END_OF_MAIN()
void init() {
    int depth, res;
    allegro_init();
    depth = desktop_color_depth();
    if (depth == 0) depth = 32;
    set_color_depth(depth);
    res = set_gfx_mode(GFX_AUTODETECT_WINDOWED, 900, 600, 0,0);
    if (res != 0) {
        allegro_message(allegro_error);
        exit(-1);
    }
    install_timer();
    install_keyboard();
    install_mouse();
    /* add other initializations here */
}
void deinit() {
    clear_keybuf();
    /* add other deinitializations here */
}

So what why does it flicker and how do I stop that. I have had issue with for loops before do they just not work whit allegro? or am I being dumb and just written something wrong?

  • It has been a while since i last used Allegro. But one thing i could reccomend you try is buffering or double buffering. https://discover.hubpages.com/technology/2D-Game-Programming-In-C-Under-Windows-Allegro-Basics-Game-Logic-of-Catch-My-Fruits This tutorial has a section about it. Basically you dont draw directly onto screen, but you draw into buffer. And once everything is drawn into buffer, you draw buffer onto screen. – Marko Taht May 12 '22 at 22:18
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community May 13 '22 at 06:02
  • 1
    What version of allegro are you using? You should use the latest, Allegro 5. – Promitheas Nikou May 13 '22 at 06:07

0 Answers0