libgdx ActorGestureListener.pan() parameters not moving actor in smooth line

Posted by Roar Skullestad on Game Development See other posts from Game Development or by Roar Skullestad
Published on 2013-12-28T05:06:31Z Indexed on 2014/06/06 9:43 UTC
Read the original article Hit count: 345

Filed under:
|

I override the pan method in ActorGestureListener to implement dragging actors in libgdx (scene2d).

When I move individual pieces on a board they move smoothly, but when moving the whole board, the x and y coordinates that is sent to pan is "jumping", and in an increasingly amount the longer it is dragged.

These are an example of the deltaY coordinates sent to pan when dragging smoothly downwards:

 1.1156368
-0.13125038
-1.0500145
 0.98439217
-1.0500202
 0.91877174
-0.984396
 0.9187679
-0.98439026
 0.9187641
-0.13125038

This is how I move the camera:

public void pan (InputEvent event, float x, float y, float deltaX, float deltaY) {
    cam.translate(-deltaX, -deltaY);

I have been using both the delta values sent to pan and the real position values, but similar results. And since it is the coordinates that are wrong, it doesn't matter whether I move the board itself or the camera.

What could the cause be for this and what is the solution?

When I move camera only half the delta-values, it moves smoothly but only at half the speed of the mouse pointer:

cam.translate(-deltaX / 2, -deltaY / 2);

It seems like the moving of camera or board affects the mouse input coordinates. How can I drag at "mouse speed" and still get smooth movements?

(This question was also posted on stackoverflow: http://stackoverflow.com/questions/20693020/libgdx-actorgesturelistener-pan-parameters-not-moving-actor-in-smooth-line)

© Game Development or respective owner

Related posts about java

Related posts about libgdx