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

[Allegro 4.x] Wyświetlanie bitmapy po wciśnięciu przycisku

Ostatnio zmodyfikowano 2015-05-28 20:29
Autor Wiadomość
BadBullPL
Temat założony przez niniejszego użytkownika
[Allegro 4.x] Wyświetlanie bitmapy po wciśnięciu przycisku
» 2015-05-28 18:16:30
Mam oto taki kod:
C/C++
#include <allegro.h>
BITMAP * kursor;

void laduj_kursor()
{
    kursor = load_bitmap( "kursor.bmp", NULL );
   
};
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();
    set_color_depth( 16 );
    set_gfx_mode( GFX_AUTODETECT_WINDOWED, 800, 600, 0, 0 );
    BITMAP * bufor = NULL;
    BITMAP * ludek = NULL;
    BITMAP * button = NULL;
    button = load_bmp( "button.bmp", default_palette );
    ludek = load_bmp( "ludek.bmp", default_palette );
    bufor = create_bitmap( 800, 600 );
    laduj_kursor();
    install_mouse();
    //enable_hardware_cursor();
   
    //select_mouse_cursor(MOUSE_CURSOR_ALLEGRO);
   
    show_mouse( NULL );
    set_mouse_sprite( kursor );
    unscare_mouse();
    //clear_to_color(screen,makecol(128,128,128));
    int button_x = 100;
    int button_y = 100;
    int ludek_x = 100;
    int ludek_y = 100;
   
    while( !key[ KEY_ESC ] )
    {
        bool czy_wcisnieto = false;
        clear_to_color( bufor, makecol( 100, 100, 100 ) );
        myszka();
       
        masked_blit( button, bufor, 0, 0, button_x, button_y, button->w, button->h );
        masked_blit( kursor, bufor, 0, 0, mx, my, kursor->w, kursor->h );
        if( mb == 1 && mx >= 100 && mx <= 100 + button->w && my <= 100 + button->h && my >= 100 )
        {
            czy_wcisnieto = true;
        }
        if( czy_wcisnieto == true )
        {
            masked_blit( ludek, bufor, 0, 0, ludek_x, ludek_y, ludek->w, ludek->h );
        }
        blit( bufor, screen, 0, 0, 0, 0, 800, 600 );
       
       
        clear_keybuf();
    }
    destroy_bitmap( bufor );
    destroy_bitmap( ludek );
    destroy_bitmap( button );
   
   
    allegro_exit();
    return 0;
}
END_OF_MAIN();

I chodzi o to że obrazek ludka  wyswietla się tylko wtedy jak lewy przycisk myszy jest wcisnięty lub przytrzymany a mi chodzi o to żeby po jednokrotnym wciśnięciu bitmapa ludka była już ciągle widoczna.
P-132902
SeaMonster131
» 2015-05-28 20:25:48
bool czy_wcisnieto = false;
To znajduje się w pętli.
P-132907
BadBullPL
Temat założony przez niniejszego użytkownika
» 2015-05-28 20:29:54
Ok dzięki zamykam
P-132909
« 1 »
  Strona 1 z 1