grabon Temat założony przez niniejszego użytkownika |
[Allegro] Mrugająca mysz » 2008-08-18 12:15:04 Mam problem jak w temacie, jako że od niedawna zainteresowałem się biblioteką allegro nie wiem w czym tkwi problem, zrobiłem obraz kursora i po wstawieniu go w kurs z tej strony "Mysz" działa poprawnie, ale już po dostosowaniu tutka do mojego programu zaczęły się problemy, kursor ciągle miga. Poniżej podaje kod: BITMAP * kursor = NULL;
void laduj_kursor() { kursor = load_pcx( "Data/kur.pcx", NULL ); if( !kursor ) { set_gfx_mode( GFX_TEXT, 0, 0, 0, 0 ); allegro_message( " Kursor nie wczytany" ); allegro_exit(); } }; int mx = 0, my = 0, mb = 0; void myszka() { if( mx != mouse_x || my != mouse_y || mb != mouse_b ) { mx = mouse_x; my = mouse_y; mb = mouse_b; } };
int main() { allegro_init(); install_keyboard(); install_mouse(); set_color_depth( 16 ); set_gfx_mode( GFX_AUTODETECT, 1024, 768, 0, 0 ); BITMAP * bufor = NULL; BITMAP * ananas = NULL; BITMAP * agrest = NULL; BITMAP * tlo = NULL; bufor = create_bitmap( 1024, 768 ); ananas = load_pcx( "Data/anana.pcx", default_palette ); agrest = load_pcx( "Data/agre.pcx", default_palette ); tlo = load_pcx( "Data/tlo.pcx", default_palette ); int tlo_x = 0, tlo_y = 0; int agrest_x = 153, agrest_y = 9; int ananas_x = 400, ananas_y = 100; laduj_kursor(); while( !key[ KEY_ESC ] ) { if(( key[ KEY_A ] ) &&( agrest_x > 15 ) ) agrest_x--; if(( key[ KEY_D ] ) &&( agrest_x < 805 ) ) agrest_x++; if(( key[ KEY_W ] ) &&( agrest_y > 0 ) ) agrest_y--; if(( key[ KEY_S ] ) &&( agrest_y < 704 ) ) agrest_y++; clear_to_color( bufor, makecol( 150, 150, 150 ) ); myszka(); rest( 10 ); masked_blit( tlo, bufor, 0, 0, tlo_x, tlo_y, tlo->w, tlo->h ); masked_blit( agrest, bufor, 0, 0, agrest_x, agrest_y, agrest->w, agrest->h ); masked_blit( ananas, bufor, 0, 0, ananas_x, ananas_y, ananas->w, ananas->h ); masked_blit( ananas, bufor, 0, 0, 350, 280, ananas->w, ananas->h ); masked_blit( ananas, bufor, 0, 0, 350, 200, ananas->w, ananas->h ); masked_blit( agrest, bufor, 1, 1, 100, 300, agrest->w, agrest->h ); if( agrest_y < 704 ) agrest_y++; if( agrest_y == 704 ) { agrest_y = - 64; if( agrest_y < 704 ) agrest_y++; } textprintf_ex( bufor, font, 170, 20, makecol( 0, 0, 200 ), - 1, "Myszka x = %d, y = %d, klawisz = %d !", mx, my, mb ); blit( bufor, screen, 0, 0, 0, 0, 1024, 768 ); clear_keybuf(); show_mouse( screen ); set_mouse_sprite( kursor ); unscare_mouse(); }
|
|
DejaVu |
» 2008-08-18 12:22:25 |
|
grabon Temat założony przez niniejszego użytkownika |
» 2008-08-18 22:01:35 Pomogło, ale występuje inny problem, tło myszy nie do końca jest przezroczyste, mianowicie jest zależne od lini: clear_to_color( bufor, makecol( 0, 0, 0 ) );
Mimo iż tło kursora ma kolor 255,0,255. Wszystko jest ok. do momentu ruchu myszy. Pozdrawiam |
|
DejaVu |
» 2008-08-18 22:34:10 Możesz wkleić ten poprawiony kod? Może poprostu w złym miejscu masz wywołanie funkcji pokazującej mysz... |
|
grabon Temat założony przez niniejszego użytkownika |
» 2008-08-19 10:25:33 Podaje kod: BITMAP * kursor = NULL;
void laduj_kursor() { kursor = load_pcx( "Data/kur.pcx", default_palette ); if( !kursor ) { set_gfx_mode( GFX_TEXT, 0, 0, 0, 0 ); allegro_message( " Kursor nie wczytany" ); allegro_exit(); } }; int mx = 0, my = 0, mb = 0; void myszka() { if( mx != mouse_x || my != mouse_y || mb != mouse_b ) { mx = mouse_x; my = mouse_y; mb = mouse_b; } };
int main() { allegro_init(); install_keyboard(); install_timer(); set_color_depth( 16 ); set_gfx_mode( GFX_AUTODETECT, 1024, 768, 0, 0 ); set_palette( default_palette ); BITMAP * bufor = NULL; BITMAP * ananas = NULL; BITMAP * agrest = NULL; BITMAP * tlo = NULL; bufor = create_bitmap( 1024, 768 ); ananas = load_pcx( "Data/anana.pcx", default_palette ); agrest = load_pcx( "Data/agre.pcx", default_palette ); tlo = load_pcx( "Data/tlo.pcx", default_palette ); int tlo_x = 0, tlo_y = 0; int agrest_x = 153, agrest_y = 9; int ananas_x = 400, ananas_y = 100; laduj_kursor(); while( !key[ KEY_ESC ] ) { if(( key[ KEY_A ] ) &&( agrest_x > 15 ) ) agrest_x--; if(( key[ KEY_D ] ) &&( agrest_x < 805 ) ) agrest_x++; if(( key[ KEY_W ] ) &&( agrest_y > 0 ) ) agrest_y--; if(( key[ KEY_S ] ) &&( agrest_y < 704 ) ) agrest_y++; install_mouse(); myszka(); clear_to_color( bufor, makecol( 150, 150, 150 ) ); rest( 10 ); masked_blit( tlo, bufor, 0, 0, tlo_x, tlo_y, tlo->w, tlo->h ); masked_blit( agrest, bufor, 0, 0, agrest_x, agrest_y, agrest->w, agrest->h ); masked_blit( ananas, bufor, 0, 0, ananas_x, ananas_y, ananas->w, ananas->h ); masked_blit( ananas, bufor, 0, 0, 350, 280, ananas->w, ananas->h ); masked_blit( ananas, bufor, 0, 0, 350, 200, ananas->w, ananas->h ); masked_blit( agrest, bufor, 1, 1, 100, 300, agrest->w, agrest->h ); if( agrest_y < 704 ) agrest_y++; if( agrest_y == 704 ) { agrest_y = - 64; if( agrest_y < 704 ) agrest_y++; } textprintf_ex( bufor, font, 170, 20, makecol( 0, 0, 200 ), - 1, "Myszka x = %d, y = %d, klawisz = %d !", mx, my, mb ); set_mouse_sprite( kursor ); show_mouse( bufor ); unscare_mouse(); blit( bufor, screen, 0, 0, 0, 0, 1024, 768 ); } while( !key[ KEY_ESC ] ); show_mouse( NULL ); remove_timer(); destroy_bitmap( kursor );
|
|
DejaVu |
» 2008-08-19 10:38:17 set_mouse_sprite( kursor ); show_mouse( bufor ); unscare_mouse();
Wyciągnij pierwszą linijkę przed pętlę while(). Drugą zostaw. Trzecią wykomentuj i sprawdź czy działa. /edit: Wywal też z kodu linijkę: while( !key[ KEY_ESC ] ); Jest ona prawie na samym końcu programu i nic ona nie robi poza tym, że może zaburzyć pracę programu - tj. nie wyjść z niego po pierwszym naciśnięciu ESC. |
|
grabon Temat założony przez niniejszego użytkownika |
» 2008-08-19 10:45:29 Nic nie daje, tylko tyle, że mój kursor znika i pokazuje się kursor windy, z tym samym tłem co poprzednio, czyli mrugające szare paski, sam kursor nie mruga. |
|
DejaVu |
» 2008-08-19 10:54:06 Hm... to jak będę w domu, to spojrzę na to dokładniej. |
|
« 1 » 2 |