-
clearing the screen
umm... i want to animate a bitmap according to what key the user is pressing. But when I use no clear screen functions the old bitmap is left behind. When I use a clear screen function then it is really sketchy. I used man different types of clear screen such as clear_to_color etc. I am not sure what I am doing wrong. Oh and I am using the allegro library with Dev C++ and windows 98 (if that matters)
Code:
#include <allegro.h>
int main()
{
allegro_init();
set_gfx_mode(GFX_SAFE, 640, 480, 0, 0);
set_color_depth(16); // Set the color depth
install_keyboard();
BITMAP *pic;
pic = load_bitmap("plane.bmp", NULL); // Load our picture
int x=0, y=0;
acquire_screen();
while(!key[KEY_ESC])
{if (key[KEY_UP])
{y++;}
if (key[KEY_DOWN])
{y--;}
clear_bitmap(screen);
for (int i=0 ; i < 1; i++) { clear_bitmap(screen);
vsync();
blit(pic, screen, x, y, 0, 0, 640, 480);
}
}
release_screen();
destroy_bitmap(pic);//Release the bitmap data
allegro_exit();
return 0;
}
END_OF_MAIN();
-
try this clear screen function:
Code:
void cls()
{
union REGS i,o;
i.h.ah = 6;
i.h.bh = 7;
i.h.ch = 0;
i.h.dh = 24;
i.h.al = 0;
i.h.cl = 0;
i.h.dl = 79;
int86(16,&i,&o);
gotoxy(1,1);
}
if your compiler doesn't have gotoxy(x,y) then add this function too:
Code:
void gotoxy(int x, int y)
{
HANDLE hConsoleOutput;
COORD dwCursorPosition;
dwCursorPosition.X = x;
dwCursorPosition.Y = y;
hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hConsoleOutput,dwCursorPosition);
}
dont forget to include windows.h for the gotoxy function
-
will that code work for clearing text too?
-
i belive it clears the whole screen doesn't matter whats on it. (i hope :D )