按住TouchDown的Libgdx函数是什么?

3

在libGdx(Android)中是否有类似于触摸事件的等效方法,即当用户触摸屏幕并持续按住手指时,例如touchhelddown方法?

1个回答

8
你可以使用GestureDetector。它实现了InputAdapter,因此你可以使用它代替你的InputAdapter或与你的InputAdapter一起使用InputMultiplexer
你需要向它提供一个GestureListener。当检测到支持的手势时,GestureDetector会调用GestureListener的方法。这些方法和手势包括:
public boolean touchDown (int x, int y, int pointer);
public boolean tap (int x, int y, int count);
public boolean longPress (int x, int y);
public boolean fling (float velocityX, float velocityY);
public boolean pan (int x, int y, int deltaX, int deltaY);
public boolean zoom (float originalDistance, float currentDistance);
public boolean pinch (Vector2 initialFirstPointer, Vector2 initialSecondPointer, 
                      Vector2 firstPointer, Vector2 secondPointer);

您可以扩展GestureAdapter并覆盖您感兴趣的方法。在您的情况下,您将覆盖longPress方法。您还可以将longPressDuration作为参数提供给构造函数。


1
我仍然觉得扩展GestureAdapter有点棘手,作为一个新手,您能否提供一个正确的示例来帮助我完成这个过程?我得到了一些奇怪的结果!我想在长按持续时间内缩放精灵,然后在释放按键后它会恢复到原始大小。 - user1320651

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接