我希望 LibGDX 触摸板在点击屏幕的其他位置时移动到新位置,但我希望它立即使用



我有一个LibGDX程序,当程序在Android中运行时,我在其中添加了一个触摸板。触摸板按预期工作。

我已经设置了它,以便如果我触摸屏幕上不是触摸板或任何 UI 按钮的区域,它会将触摸板移动到该位置。那件作品也正常工作。

但是,要在将触摸板移动到新位置后使用它,我必须抬起手指,然后将其放回原处。将手指放在新位置后,我无法开始拖动以使用触摸板。

创建触摸板以完全标准的方式完成:

touchpad = new Touchpad(5, touchpadStyle);

移动触摸板在这里完成:

@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
Vector3 vec = new Vector3(screenX, screenY, 0);
uiStage.getCamera().unproject(vec);
touchpad.setPosition(vec.x-touchpad.getWidth()/2, vec.y - touchpad.getHeight()/2);
return false;
}

我正在考虑可能扩展触摸板类,但我不确定是否可以这样做,和/或者是否有一种更简单的方法可以做到这一点,但我还没有发现。

提前感谢!

stage.addListener(new InputListener()
{
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button)
{
System.out.println("event = " + event + ", x = " + x + ", y = " + y + ", pointer = " + pointer + ", button = " + button);
if (!touchpad.isTouched())
{
touchpad.setPosition(x, y, Align.center);
touchpad.fire(event);
}
return super.touchDown(event, x, y, pointer, button);
}
});

相关内容