Sign in to follow this  
Meagermanx

Getting the cursor to appear over a background using Allegro

Recommended Posts

Meagermanx    220
Okay, so I've got this cursor sprite, and this background, and I really want to draw the cursor over the background. The problem, though, is that when I rectfill the screen with my color, I can only see the mouse when it moves. Code:
#include <allegro.h>

BITMAP *cursor;
BITMAP *buffer;
int main()
{
    allegro_init();
    install_keyboard();
    install_mouse();
    set_color_depth(16);
    set_gfx_mode(GFX_AUTODETECT,640,480,0,0);
    
    cursor = load_bitmap("cursor.bmp",NULL);
    buffer = create_bitmap(640,480);
    
    set_mouse_sprite(cursor);

    show_mouse(screen);
    
    while(!key[KEY_ESC])
    {
         acquire_screen();
         rectfill(buffer,0,0,640,480,makecol(40,120,40));
         draw_sprite(screen,buffer,0,0);         
         release_screen();
    }
    
    
    
}
END_OF_MAIN();

The green background color is only temporary, so that I don't have to draw a sprite. But my question is how can I get the mouse to appear over my other sprites? Thanks.

Share this post


Link to post
Share on other sites
AsOne    326
The problem is that you set the mouse to appear on the screen, but the buffer gets blitted to the screen each time, which erases the mouse cursor.


while(!key[KEY_ESC])
{
// clear buffer to color
clear_to_color(buffer, makecol(40, 120, 40));
// set mouse to show on buffer
show_mouse(buffer);
acquire_screen();
// blit buffer to screen
blit(buffer, screen, 0, 0, 0, 0, 640, 480);
release_screen();
}
// hide mouse
show_mouse(NULL);
// destroy buffer
destroy_bitmap(buffer);




That should work. show_mouse(NULL) must be called before destroying the buffer bitmap, otherwise allegro will attempt to draw the cursor on the buffer, resulting in errors.

Hope this helped.

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