Hey so I was trying to make a program where you can draw a line from a point to where your mouse is but I am having trouble figuring out how to delete the line after it has been drawn.
#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();
You will need to store the coordinates of the lines in a data structure of some sort (e.g., an array of structs). When you want to delete a line, remove it from the data structure.
Your drawing code then looks like:
And don’t call acquire/release screen. They generally aren’t needed, and you’ll give yourself a lot of problems if you misuse them.