0
在我的遊戲中,用戶應該用一個手指在屏幕左側移動玩家,並且能夠用右手指拍攝。問題是,當射擊時,玩家不能再移動。我發現了一些相關的問題,但沒有人幫助我。我嘗試使用2個不同的GestureListener類。其中一個檢查屏幕右側是否被觸摸,另一個檢查左側,仍然不起作用。libgdx多個平移事件
這是第一類
public boolean pan(float x, float y, float deltaX, float deltaY) {
lastTouch = new Vector2(x, y).sub(deltaX, deltaY);
Vector2 newTouch = new Vector2(x, y);
Vector2 delta = newTouch.cpy().sub(lastTouch);
if(lastTouch.x < Gdx.graphics.getWidth()/2 && newTouch.x < Gdx.graphics.getWidth()/2) {
stage.getPlayer().move(new Vector2(delta.x, -delta.y));
}
lastTouch = newTouch;
return true;
}
的盤法這是第二類的方法
public boolean pan(float x, float y, float deltaX, float deltaY) {
lastTouch = new Vector2(x, y).sub(deltaX, deltaY);
Vector2 newTouch = new Vector2(x, y);
Vector2 delta = newTouch.cpy().sub(lastTouch);
if(lastTouch.x > Gdx.graphics.getWidth()/2 && newTouch.x > Gdx.graphics.getWidth()/2){
if(shoot) {
bullets.add(new Bullet(WorldUtils.createBullet(stage.getWorld(), stage.getPlayer().getBody().getPosition().x+70, stage.getPlayer().getBody().getPosition().y, new Vector2(delta.x, -delta.y)), new Vector2(delta.x, -delta.y)));
shoot = false;
}
stage.getPlayer().turn(new Vector2(delta.x, -delta.y));
}
lastTouch = newTouch;
return true;
}
感謝您在LibGDX
不,它並沒有解決它 – DreamsInHD
這可能是泛方法只適用於單手指。您可以嘗試將其轉換爲使用touchDown和touchUp方法,該方法具有手指計數的參數指針。 – dfour
它的工作原理!非常感謝! – DreamsInHD