2012-07-15 95 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; 
    }