refresh screen problem .
chin jiunn gai

#include <conio.h>
#include "allegro.h"
#define MODE GFX_AUTODETECT_WINDOWED
#define WIDTH 800
#define HEIGHT 600

void init(){
allegro_init();
install_keyboard();
install_mouse();
install_timer();
set_color_depth(16);
set_gfx_mode(MODE, WIDTH, HEIGHT, 0, 0);
}

int main ()
{
int x = 0;
int y = 0;
init();
text_mode(-1);
while(!key[KEY_ESC])
{
textprintf(screen,font,200,200,makecol(255,255,255), "Location = %i x %i", x++, y++);
rest(10);
}
allegro_exit();
return 0;
}
END_OF_MAIN();

-------------------------------------------------------------------------------

how can i refresh the x,y value ? my output is overlaping ..
see the attachment

ReyBrujo

The easiest way, before the textprintf, call clear_bitmap(screen); or clear_screen(); (dunno which one will work for you, as you seem to have an old version of Allegro, it may also work clear(screen);).

The better way is using a double buffer instead of drawing directly on the screen, like:

1#include <allegro.h>
2#define MODE GFX_AUTODETECT_WINDOWED
3#define WIDTH 800
4#define HEIGHT 600
5 
6 
7void init(){
8allegro_init();
9install_keyboard();
10install_mouse();
11install_timer();
12set_color_depth(16);
13set_gfx_mode(MODE, WIDTH, HEIGHT, 0, 0);
14}
15 
16int main ()
17{
18BITMAP *buffer;
19int x = 0;
20int y = 0;
21init();
22text_mode(-1);
23 
24buffer = create_bitmap(WIDTH, HEIGHT);
25while(!key[KEY_ESC])
26{
27 clear_bitmap(buffer);
28 textprintf(buffer,font,200,200,makecol(255,255,255), "Location = %i x %i", x++, y++);
29 vsync();
30 blit(buffer, screen, 0, 0, 0, 0, WIDTH, HEIGHT);
31}
32 
33destroy_bitmap(buffer);
34allegro_exit();
35return 0;
36}
37END_OF_MAIN()

Don't include conio.h, and don't put semicolon at the end of END_OF_MAIN.

Thread #558081. Printed from Allegro.cc