Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Lag when object follows mouse

This thread is locked; no one can reply to it. rss feed Print
Lag when object follows mouse
Ariesnl
Member #2,902
November 2002
avatar

In windows (and also linux) when dragging an object is "glued" to the mousecursor. no matter how fast you move it stays on.

How is this achieved ? when updating my object with mouse.dx and mouse.dy there is always some lag between mouse position and object position.

any ideas ?

Perhaps one day we will find that the human factor is more complicated than space and time (Jean luc Picard)
Current project: [Star Trek Project ] Join if you want ;-)

bamccaig
Member #7,536
July 2006
avatar

I'm not sure, but are you redrawing every time the mouse position changes? Your mouse can probably move more granularly than 60 times a second. Just a hunch, but not sure it makes sense. I'm assuming the mouse cursor is a hardware/system mouse.

Ariesnl
Member #2,902
November 2002
avatar

True, but the windows ( in windows and in linux) stick nicely to the mousecursor when you drag them. So there has to be another way. ???

Perhaps one day we will find that the human factor is more complicated than space and time (Jean luc Picard)
Current project: [Star Trek Project ] Join if you want ;-)

Audric
Member #907
January 2001

The window manager is responsible for drawing both window frames and "system" mouse cursor, so it has no problem synchronizing the two.

If the lag is distracting in your game, you may want to stop using the system mouse cursor, and draw your own during your draw step.

Another approach, to try reduce lag, is to peek the event queue for the latest mouse position (or call al_get_mouse_state()), and use that to position the moving thing. It might save you half a frame worth of distance.

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

First, you need to be more specific. What OS are you using? Are you using Allegro to draw a system cursor? Or are you drawing the mouse yourself? How are you monitoring the mouse position? On Windows, you can set a callback process that can process mouse moves.

Ariesnl
Member #2,902
November 2002
avatar

I'm making a GUI system for allegro, so it's the lag between the mouse event and the actual mouse position. Allegro is drawing the system cursor, and I''m using the event system

Perhaps one day we will find that the human factor is more complicated than space and time (Jean luc Picard)
Current project: [Star Trek Project ] Join if you want ;-)

Edgar Reynaldo
Major Reynaldo
May 2007
avatar

Mark Oates
Member #1,146
March 2001
avatar

I had a similar situation here. You may be looking for al_get_mouse_cursor_position()? In my case, my previous implementation wasn't setting the position to the actual mouse cursor at that exact moment, causing things to go crazy. Maybe it's related.

--
Visit CLUBCATT.com for cat shirts, cat mugs, puzzles, art and more <-- coupon code ALLEGRO4LIFE at checkout and get $3 off any order of 3 or more items!

AllegroFlareAllegroFlare DocsAllegroFlare GitHub

Niunio
Member #1,975
March 2002
avatar

Ariesnl said:

I'm making a GUI system for allegro, so it's the lag between the mouse event and the actual mouse position. Allegro is drawing the system cursor, and I''m using the event system

I did finished my own GUI system for the engine I'm creating. I wrote it in Object Pascal, I'm drawing the mouse cursor by myself and I haven't such "lag" drawing the mouse.

My system is quite complex (mouse is an independent object and cursor is managed by GUI and everything is decoupled...) but in short is similar to this:

PROCEDURE RenderMouseCursor
VAR
    State: ALLEGRO_MOUSE_STATE;
BEGIN
    al_get_mouse_state (State);
    al_draw_bitmap (
      MousCursorBmp,
      MouseOffsetX + State.X, MouseOffsetY + State.Y,
      0
    )
END;

-----------------
Current projects: Allegro.pas | MinGRo

Go to: