Jump to content
  • Advertisement
Sign in to follow this  
Meagermanx

Changing the cursor with Allegro

This topic is 4826 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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()
{
    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
Advertisement
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
Well, according to the code you listed, you never actually declared screen. That is why it isn't drawing to the screen.

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!