tags:

views:

41

answers:

1

Alright, I have a simple boolean at the top of this class, standing. In the thread, I have the following code:

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


}

Why won't it switch the dawing back to standing, that's all I want. Click it once and it goes to crouching, click it again and it stands. I know this is stupid simple, but I can't get it right for some reason. Thanks in advance.

+2  A: 

Trying to read the unformatted code I see; If standing is true, you set it to false. then you test if standing is false, which sets it back to true. It should be else if, not if.

KevinDTimm