Changing the cursor with Allegro

Recommended Posts

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

BITMAP *cursor;

int main()
{

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 on other sites
Is cursor non zero, i.e., did it actually manage to load it?

Share on other sites
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 on other sites
Well, according to the code you listed, you never actually declared screen. That is why it isn't drawing to the screen.

Share on other sites
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 on other sites
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 on other sites
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 on other sites
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 on other sites
aaaaaaaah. Thanks, guys. I appreciate your help.

Create an account

Register a new account

• Forum Statistics

• Total Topics
627718
• Total Posts
2978790

• 9
• 21
• 14
• 12
• 42