Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Problems with mouse flicker

This thread is locked; no one can reply to it. rss feed Print
Problems with mouse flicker
cdxrd
Member #7,061
March 2006

Ok, been playing with this for a couple days now and I have the mouse working in my menu, but there is an awful flicker.

All im doing is using double buffering. I read in the manual that you need to hide the mouse when drawing and then show it again when your done or 'bad stuff will happen' but this doesnt help. Im using a custom bitmap, it loads and displays ok.

Here is some pseudo showing how Im doing it:

show_mouse(screen);
Do {
scare_mouse();
// insert drawing routines for menu, check for mouseovers, etc
// blit to screen
unscare_mouse();

This causes a horrid flicker tho. Ive checked the exmouse example and they are using it the same way, except when they show their custom mouse cursor its not in a loop, it just waits for a readkey() .

I've also tried showing the mouse on the buffer, and still got the flicker. Im tempted to just draw my cursor as a sprite and set x & y via the mouse_x & y instead of using allegros routines.

spunit262
Member #5,545
February 2005
avatar

I alway use the hardwere mouse now to avoid that problem.
I also think the hardwere mouse looks better, why isn't it the default?

Kitty Cat
Member #2,815
October 2002
avatar

Quote:

I also think the hardwere mouse looks better, why isn't it the default?

Because then the mouse mickeys won't work.

But basically what you have to do is eith er use a hardware cursor, or double-buffer the mouse. Like so:

1/* Try to enable a hardware cursor */
2enable_hardware_cursor();
3show_mouse(screen);
4/* If not, fall back to double-buffering */
5if(!(gfx_capabilities&GFX_HW_CURSOR))
6 show_mouse(NULL);
7 
8while(game_loop)
9{
10 logic();
11 draw(buffer);
12 
13 if(!(gfx_capabilities&GFX_HW_CURSOR))
14 draw_sprite(buffer, mouse_sprite, mouse_x, mouse_y);
15 blit(buffer, screen, 0, 0, 0, 0, buffer->w, buffer->h);
16 clear_bitmap(buffer);
17}

--
"Do not meddle in the affairs of cats, for they are subtle and will pee on your computer." -- Bruce Graham

Evert
Member #794
November 2000
avatar

Quote:

Because then the mouse mickeys won't work.

May not work as you expect. The mouse mickeys will work, but you won't get an infinate range of movement in, say, X11.
For this reason we couldn't make the hardware mouse the default behavior (it would break existing programmes).

cdxrd
Member #7,061
March 2006

Well, thanx for the help, I think I am going to do it like you suggested Kitty Cat. I was drawing the mouse as a sprite, I was trying to use allegro's routines:

set_mouse_sprite(mouse_cursor);
set_mouse_sprite_focus(3, 3);

And using the scare, unscare();

But that way is giving way too much flicker, and I really dont want to use the hardware mouse, so displaying it as a sprite will probably be the easiest solution..

See how it is? The one time I go and do my reasearch and look it up in the manual and it turns out to be a horrid way of doing it.. =)

Evert
Member #794
November 2000
avatar

Quote:

I really dont want to use the hardware mouse

Why? It's by far the best way of displaying the mouse if your OS supports it.

Quote:

The one time I go and do my reasearch and look it up in the manual and it turns out to be a horrid way of doing it

Meaning?

cdxrd
Member #7,061
March 2006

Meaning exactly what I said..

When I use allegro's mouse routines for a custom cursor, I get a horrid flicker, and nothing I have done so far is eliminating it. If I use the hardware cursor, will it still show me the custom cursor I have chosen or does it limit me to the stock OS default one?

Kitty Cat
Member #2,815
October 2002
avatar

It will show the one you select, as long as the OS supports it (eg. isn't larger than 32x32 in Windows). Can't hurt to try.. it's only a few lines of code. :)

--
"Do not meddle in the affairs of cats, for they are subtle and will pee on your computer." -- Bruce Graham

Evert
Member #794
November 2000
avatar

Quote:

If I use the hardware cursor, will it still show me the custom cursor I have chosen or does it limit me to the stock OS default one?

There wouldn't be much point if all you could get were the default OS cursors.

cdxrd
Member #7,061
March 2006

Even after enabling the hardware cursor, the flicker is just as horrid as before. So I just resorted to a good old standby. Move the sprite to Mouse_x & y.. No flicker, etc... Really no difference there except how its drawn, I'm still detecting clicks and setting my bounding boxes, only difference is I gotta remember to blit the cursor.. big deal.

Evert
Member #794
November 2000
avatar

Quote:

Even after enabling the hardware cursor, the flicker is just as horrid as before.

Did you check you actually get a hardware cursor? Can you post your code?

Quote:

only difference is I gotta remember to blit the cursor.. big deal.

The update rate of your on-screen mouse pointer is also limited to your framerate, and if you don't redraw frames unless things have changed (which is normally a good idea) it won't update either (basically forcing you to do the update whenever you can).

Go to: