#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();
Changing the cursor with Allegro
According to what I've been reading in the Allegro manual, this should change the sprite:
Can anyone tell me why this doesn't change the cursor to whatever graphic cursor.bmp holds? Thanks.
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:
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.
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.
Well, according to the code you listed, you never actually declared screen. That is why it isn't drawing to the screen.
Are you refering to the acquire_screen() function?
Okay, this is my main loop now, and it still doesn't work:
shouldn't this draw to the screen? Thanks for any provided help.
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.
Sorry, I was thinking about SDL not allegro...
Try this for your init code:
You shouldn't have to draw the cursor using draw_sprite(), it should appear from this call.
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.
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?
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?
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)!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement