1

Hey first off I just want to say i am a complete noob at allegro and pretty much just started. What I want to do is keep a line on the screen for a second, but then have it disappear. Right now all that is happening is the line is just staying on the screen.

Here is my code:

#include <allegro.h>
#include <cstdlib>

BITMAP *buffer;

int main(){

    allegro_init();
    install_mouse();
    install_keyboard();
    set_color_depth(16);
    set_gfx_mode( GFX_AUTODETECT, 640, 480, 0, 0);
    buffer = create_bitmap( 640, 480);

    while( !key[KEY_ESC]){


     if (key[KEY_SPACE]){

      line( buffer, 30, 450, mouse_x, mouse_y, makecol( 255, 0, 0));

      }

    draw_sprite( screen, buffer, 0, 0);
    release_screen();

    rest(10);

    }

    return 0;

}
END_OF_MAIN();
turnt
  • 3,235
  • 5
  • 23
  • 39
Napplesauce
  • 47
  • 1
  • 6
  • You may want to research the `release_screen()` function, because I am pretty sure it isn't necessary where you are using it here. The `draw_sprite()` function, as well as all the standard drawing functions, takes care of the locking and releasing of the screen for you. Unless you are doing something fairly advanced, you will likely never have to manually release the screen. – Alex Feb 16 '13 at 07:56

1 Answers1

0

What is happening here is that you are just repeatedly drawing the line in the same place, without ever clearing the screen. You can clear the screen with:

clear_to_color(buffer,makecol(r,g,b));

The simplest solution is to add this line using your preferred RGB values to the start of your loop.

Alex
  • 671
  • 3
  • 11
  • 25