salve. il mio problema è il seguente (uso la libreria grafica allegro):
- ho creato un metodo per spostare un oggetto (Es un rettangolo) trascinandolo con il mouse, il mio problema sta nel fatto che spostando l'oggetto esso copre quello su cui passa, e questo è logico.
il problema sta nel fatto che se di sfondo ho un immagine (o un altro oggetto) devo rigenerare ciò su cui il rettangolo è passato spostandosi. Per risolvere questo problema ho pensato che ad ogni spostamento dell'oggetto (che sto trascinando) avrei potuto riscrivere tutto lo sfondo, ricaricando ogni volta l'immagine di sfondo sopra a tutto (alternando sfondo e oggetto). Facendo così però si ottiene un effetto molto fastidioso, legato al fatto che viene impiegato un tempo non indifferente a rigenerare lo schermo e riscrivere l'oggetto che sto spostando in posizione diversa.



se non avete capito il mio problema vi posto il codice:

codice:
include <allegro.h>
#define ALTEZZA 800
#define LARGHEZZA 600
void init();
void deinit();

int main() {
	init();

    int x1=50,x2=x1+200,y1=60,y2=y1+200;	
    set_gfx_mode(GFX_AUTODETECT_WINDOWED, LARGHEZZA, ALTEZZA, 0, 0);
    clear_to_color(screen,makecol(255,255,255));
    show_mouse(screen);
    rectfill(screen,x1,y1,x2,y2,makecol(0,0,255));
	


	
	for(int a=0;a<=LARGHEZZA;a+=100)
	                          line(screen,a,0,a,ALTEZZA,makecol(0,0,255));
    for(int a=0;a<=ALTEZZA;a+=100)
	                          line(screen,0,a,LARGHEZZA,a,makecol(0,0,255));
 
	                     
	
	
	
	
	
	
	

	while (!key[KEY_ESC]) {
		if((mouse_b&1)&&(mouse_x>=x1&&mouse_x<=x2)&&(mouse_y>=y1&&mouse_y<=y2))
                                   {
                                    int diff_x=mouse_x-x1,diff_y=mouse_y-y1;
                                                    while(mouse_b&1)
                                                   {
                                                    if(x1!=mouse_x-diff_x||y1!=mouse_y-diff_y)
                                                                                                                                         {
                                                                                                                                         //rectfill(screen,x1,y1,x2,y2,makecol(255,255,255));
                                                                                                                                         x1=mouse_x-diff_x;
                                                                                                                                         y1=mouse_y-diff_y;
                                                                                                                                         x2=x1+200;
                                                                                                                                         y2=y1+200;
                                                                                                                                         
                                                                                                                                         clear_to_color(screen,makecol(255,255,255));
                                                                                                                                         vsync();
                                                                                                                                         
                                                                                                                                         rectfill(screen,x1,y1,x2,y2,makecol(0,0,255));
                                                                                                                                         vsync();
                                                                                                                                         
                                                                                                                                         show_mouse(screen);
                                                                                              	                                         for(int a=0;a<=LARGHEZZA;a+=100)
	                                                                                                                                                                     {
                                                                                                                                                                         line(screen,a,0,a,ALTEZZA,makecol(0,0,255));
                                                                                                                                                                         vsync();
                                                                                                                                                                         }
                                                                                                                                         for(int a=0;a<=ALTEZZA;a+=100)
	                                                                                                                                                                   {
                                                                                                                                                                       line(screen,0,a,LARGHEZZA,a,makecol(0,0,255));
                                                                                                                                                                       vsync();
                                                                                                                                                                       }
 
                                                                                                                                         }
                                                                 
                                                                 

                                                                 }
                                                }
		             
	}

	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, 640, 480, 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 */
}