2
我有一個處理觸摸輸入的類Stage
。libGDX舞臺輸入處理
在Screen
I類設置stage
爲InputProcessor
:
stageTest = new StageTest(new ScreenViewport());
Gdx.input.setInputProcessor(stageHUD);
但現在我想力添加到Box2D的對象總是一個手勢輸入發生。
public class ActSwipe extends Actor {
private int tmpPointer;
private float
tmpX,
tmpY,
deltaX,
deltaY,
rad;
protected float
forceX,
forceY;
public ActSwipe() {
this.setName("SwipeAction");
this.setTouchable(Touchable.enabled);
this.addListener(new InputListener() {
@Override
public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
if(tmpPointer == 0) {
tmpPointer = pointer;
tmpX = x;
tmpY = y;
}
return true;
}
@Override
public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
if (tmpPointer == pointer) {
tmpPointer = 0;
deltaX = x - tmpX;
deltaY = y - tmpY;
rad = (float) Math.atan2(deltaY, deltaX);
forceX = (float) Math.cos(rad);
forceY = (float) Math.sin(rad);
}
}
});
}
}
看看這個類:'com.badlogic.gdx.input.GestureDetector'和這個wiki文章:https://github.com/libgdx/libgdx/wiki/Gesture-detection – donfuxx
對不起沒查找手勢聽衆。我希望重寫像Gdx.input.InputProcessor(新的InputProcessor(){覆蓋方法})的其他類(屏幕)中的階段輸入方法。 –