Android - 脑痉挛

时间:2010-10-16 14:39:48

标签: android

好吧,我在这堂课的顶部有一个简单的布尔,站着。在线程中,我有以下代码:

 @Override
public boolean onTouchEvent(MotionEvent event) {
    if(event.getAction() == MotionEvent.ACTION_DOWN) {
        if(standing == true){
            player.handleActionDown((int)event.getX(), (int)event.getY());
            standing = false;}
        if(standing == false){
            playerC.handleActionDown((int)event.getX(), (int)event.getY());
            standing = true;}

        //check if in the lower part of the screen we exit
        if(event.getY() > getHeight() -50 && event.getX() > getWidth() -50) {
            thread.setRunning(false);
            ((Activity)getContext()).finish();
        }else {
            Log.d(TAG, "Coords: x=" + event.getX() + ",y=" + event.getY());
        }
    }
    if(event.getAction() == MotionEvent.ACTION_UP){
        //touch was released

    }
    return true;

}

@Override
protected void onDraw(Canvas canvas) {
    canvas.drawBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.bg1),0, 0, null);
    //canvas.drawColor(Color.BLACK)
  if(standing == true){
        player.draw(canvas);
   } 
    if(standing == false){
        playerC.draw(canvas);
   }


}

为什么它不会将曙光切换回站立,这就是我想要的。单击它一次,然后进行蹲伏,再次单击它就可以了。我知道这很简单,但由于某些原因我无法做到这一点。提前谢谢。

1 个答案:

答案 0 :(得分:2)

尝试阅读我看到的无格式代码;如果stand为true,则将其设置为false。然后测试stand是否为false,将其设置为true。它应该是else if,而不是if