2012-07-15 173 views
-4

幫我在我的Adnroid內遊戲控制)安卓遊戲控制

我有2個按鈕: 移動左,向右移動。如果我們按左邊精靈向左移動,如果我們按右精靈移動。

這裏是代碼:

public boolean onTouchEvent(MotionEvent event) { 
    if (event.getAction() == MotionEvent.ACTION_DOWN || 
       event.getAction() == MotionEvent.ACTION_MOVE){ 
     touchX = event.getX(); 
    } 
    if(touchX == arrow_leftX){ 
     gameLoopThread.setRunning(false); 
    } 
    else if(touchX == arrow_leftX){ 
     playerX = playerX - xSpeed; 
    } 
    else if(touchX == arrow_rightX){ 
     playerX = playerX - xSpeed; 
    } 
    else if(touchX == arrow_rightX){ 
     gameLoopThread.setRunning(false); 
    } 
    return super.onTouchEvent(event); 
} 

所以,問題是:

它移動只剩下,我不知道如何移動嗎?

+1

什麼問題? – DrYap 2012-07-15 15:51:36

+1

您希望我們如何提供幫助? – udiboy1209 2012-07-15 15:57:03

+0

它只向左移動(我不知道如何向右移動 – user1526832 2012-07-16 04:57:46

回答

1
The Problem is here i think 

else if(touchX == arrow_rightX){ 
     playerX = playerX - xSpeed; 
    } 


else if(touchX == arrow_rightX){ 

// Here You can see that you are again subtracting the x axis from 
// playerX 
// it is clear that you are moving your image with this 
// but if you decrease value from x it shall move to lext 
// to move it to right you need to increase its value 

     playerX = playerX + xSpeed; 
    }