Lag when object follows mouse
Ariesnl

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 ?

bamccaig

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

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. ???

Audric

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

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

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

Edgar Reynaldo

I'm currently making a missile defense game and I have zero lag with the mouse. I draw my own pointer. All I do is respond to ALLEGRO_EVENT_MOUSE_AXES events.

You should show code if possible.

Mark Oates

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.

Niunio
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;

Thread #617380. Printed from Allegro.cc