Changing the cursor with Allegro

Started by
7 comments, last by Meagermanx 18 years, 9 months ago
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.
---There are 2 kinds of people: those who know hexadecimal, and those who don't.
Advertisement
Is cursor non zero, i.e., did it actually manage to load it?
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.
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.
---There are 2 kinds of people: those who know hexadecimal, and those who don't.
Well, according to the code you listed, you never actually declared screen. That is why it isn't drawing to the screen.
-----------------------------Play Stompy's Revenge! Now!
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.
---There are 2 kinds of people: those who know hexadecimal, and those who don't.
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.
-----------------------------Play Stompy's Revenge! Now!
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?
---There are 2 kinds of people: those who know hexadecimal, and those who don't.
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)!

[OpenTK: C# OpenGL 4.4, OpenGL ES 3.0 and OpenAL 1.1. Now with Linux/KMS support!]

aaaaaaaah. Thanks, guys. I appreciate your help.
---There are 2 kinds of people: those who know hexadecimal, and those who don't.

This topic is closed to new replies.

Advertisement