【问题标题】:touchdown held down libgdx触地得分按住 libgdx
【发布时间】:2012-04-08 18:54:04
【问题描述】:

在 libGdx(在 Android 中)中是否有类似 touchdown 事件的等价物 - 所以当用户触摸屏幕(并连续按住手指)时,即touchhelddown 方法?

【问题讨论】:

    标签: android libgdx


    【解决方案1】:

    您可以使用GestureDetector。它实现了InputAdapter,因此您可以使用它来代替您的 InputAdapter 或使用 InputMultiplexer 与您的 InputAdapter 一起使用。

    您需要为其提供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 作为参数提供给构造函数。

    【讨论】:

    • 仍然觉得扩展 GestureAdapter 有点时髦,作为一个菜鸟,您能否发布一个如何正确执行此操作的示例,我得到了奇怪的结果!我想在长按期间缩放一个精灵,然后在按下释放后恢复到原始大小。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-05
    • 1970-01-01
    • 1970-01-01
    • 2016-02-11
    • 2014-01-03
    • 1970-01-01
    相关资源
    最近更新 更多