0

I'm trying to have allow the user to press and hold the screen to increase the force of a jump (note jspeed2). I'm using the below code, but it doesn't do what I need.

Any suggestions?

case MotionEvent.ACTION_DOWN: {
    if (x < 600 && jspeed2 < 28) { 
        jspeed2++; 
    }
}
case MotionEvent.ACTION_UP: {
    if (x < 600) { 
        player.jump();
    }
}
CubeJockey
  • 2,209
  • 8
  • 24
  • 31
user2088880
  • 39
  • 2
  • 8
  • What does it do when it "doesn't work". It would also help to see more code, like the whole switch statment, where you declare jspeed2, and the jump() function. – DoubleDouble Dec 12 '13 at 19:49
  • Possible duplicate of [Switch without break](http://stackoverflow.com/questions/8563970/switch-without-break) – CubeJockey Jan 15 '16 at 14:56

2 Answers2

1

You may want to add a break; line to your case statements.

Take a look at this question's top answer for more explanation.

Community
  • 1
  • 1
DoubleDouble
  • 1,493
  • 10
  • 25
0
public final boolean onTouchEvent(MotionEvent event) {
    float x = event.getX();
    int maskedAction = event.getActionMasked();
    if(GameState==0){
    graj=true;
    }

    if(GameState==1){
        switch (maskedAction) {

        case MotionEvent.ACTION_UP:{if(x<600){player.jump();}   }

        case MotionEvent.ACTION_DOWN:{if(x<600&&jspeed2<7){jspeed2++;}   }
}
        return true;
        }
    else return true;
    }

and that's how jumping looks:

  public final void jump() {
        if (jumped == false) {
            sy = jspeed-GameView.jspeed2;
            jumped = true;
            l=20;
        }
user2088880
  • 39
  • 2
  • 8
  • Underneath your question, there is an "edit" button. It would be better to put this code there than in its own answer. Currently, what is it doing that "doesn't work"? – DoubleDouble Dec 12 '13 at 22:42