2017-06-28 29 views
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

回答

3

聽衆傾向於使用布爾返回值來說明輸入是否完成正在處理的天氣。當您返回true時,監聽器將停止處理進一步的操作。

GestureListener可以通過它的方法分別返回true或false來指示它是否消費了該事件,或者希望它傳遞給下一個InputProcessor。

嘗試改變返回方法爲假,看看是否能解決這個問題,否則試圖將其轉換爲使用具有參數指針的手指計數着陸和觸法

+0

不,它並沒有解決它 – DreamsInHD

+0

這可能是泛方法只適用於單手指。您可以嘗試將其轉換爲使用touchDown和touchUp方法,該方法具有手指計數的參數指針。 – dfour

+0

它的工作原理!非常感謝! – DreamsInHD