Panel użytkownika
Nazwa użytkownika:
Hasło:
Nie masz jeszcze konta?

[Allegro] Mrugająca mysz

Ostatnio zmodyfikowano 2008-08-19 15:10
Autor Wiadomość
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:

C/C++
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 ] )
   
    // klawiszologia
   
    {
        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();
       
        // PREDKOSC OBIEKTOW
        rest( 10 );
       
       
        // WYŚWIETLANIE OBRAZKÓW
       
       
        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();
       
    }
P-1340
DejaVu
» 2008-08-18 12:22:25
http://forum.ddt.pl/index.php?Tid=205&p=2
W powyższym temacie masz rozwiązany problem mrugającej myszy. Powinno Ci to w zupełności wystarczyć.
P-1341
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:
C/C++
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
P-1356
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...
P-1357
grabon
Temat założony przez niniejszego użytkownika
» 2008-08-19 10:25:33
Podaje kod:
C/C++
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 ] )
   
    // klawiszologia
   
    {
        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 ) );
       
       
        // PREDKOSC OBIEKTOW
        rest( 10 );
       
       
        // WYŚWIETLANIE OBRAZKÓW
       
       
        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 );
P-1360
DejaVu
» 2008-08-19 10:38:17
C/C++
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.
P-1361
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.
P-1362
DejaVu
» 2008-08-19 10:54:06
Hm... to jak będę w domu, to spojrzę na to dokładniej.
P-1363
« 1 » 2
  Strona 1 z 2 Następna strona