Sign in to follow this  
Meagermanx

Changing the cursor with Allegro

Recommended Posts

Meagermanx    220
According to what I've been reading in the Allegro manual, this should change the sprite:
#include <allegro.h>

BITMAP *cursor;

int main()
{
    cursor = load_bitmap("cursor.bmp",NULL);
    
    allegro_init();
    install_keyboard();
    install_timer();
    install_mouse();
    set_color_depth(16);
    set_gfx_mode(GFX_AUTODETECT,640,480,0,0);
    
    set_mouse_sprite(cursor);
        
    show_mouse(screen);
    while(!key[KEY_ESC])
    {
        
    }
    
    
    
}
END_OF_MAIN();

Can anyone tell me why this doesn't change the cursor to whatever graphic cursor.bmp holds? Thanks.

Share this post


Link to post
Share on other sites
Meagermanx    220
Augh! It didn't load right. That's weird, because that's never happened before. Lemme see if I can fix it...

EDIT:
Okay, the following code in my while() loop:
Quote:

if(cursor != 0)
{
draw_sprite(screen,cursor,0,0);
}

produces nothing, while breaking out of the loop on cursor ==ing 0, as well as trying to dsiplay the image, closes my program. So now I know what's wrong. Just not how to fix it.

Share this post


Link to post
Share on other sites
Meagermanx    220
Are you refering to the acquire_screen() function?
Okay, this is my main loop now, and it still doesn't work:

while(!key[KEY_ESC])
{
acquire_screen();
if(cursor != 0)
{
draw_sprite(screen,cursor,0,0);
}
release_screen();
}



shouldn't this draw to the screen? Thanks for any provided help.

Share this post


Link to post
Share on other sites
Stompy9999    792
Sorry, I was thinking about SDL not allegro...

Try this for your init code:

set_mouse_sprite(cursor);
set_mouse_sprite_focus(cursor->w/2, cursor->h/2);
show_mouse(screen);



You shouldn't have to draw the cursor using draw_sprite(), it should appear from this call.

Share this post


Link to post
Share on other sites
Meagermanx    220
Okay, I think the problem is with loading the bitmap into *cursor. Whenever I get it so that it should output the sprite, it crashes to windows. I can't figure out what's wrong with it, because I've never had this happen before.

Also, shouldn't set_mouse_sprite_focus(cursor->w/2,cursor->h/2); be something like set_mouse_sprite_focus(cursor->0,cursor->0);, so that the focus shifts to 0,0, the top left of the sprite, instead of width/2,height/2? Or does that focus the mouse on the middle of the screen?

Share this post


Link to post
Share on other sites
Fiddler    860
I'm 99% positive that you should only load bitmaps AFTER setting the gfx mode and color depth. Try it and see if it works (it should)!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this