-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);
} 

所以问题是:

它只向左移动,我不知道如何向右移动?

4

1 回答 1

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;
    }
于 2012-07-16T10:39:31.260 回答