1
\$\begingroup\$

I'm making some sort of clone for FlappyBird, but with some adjustments.

I want to change from the FlappyBird's mechaninc of jumping to make the bird raise as long as the player is long-pressing the screen. I've tried to change this:

@Override
    public boolean onTouchEvent(MotionEvent event) {
        int action = event.getAction();
        if(action==MotionEvent.ACTION_DOWN){
            valo=-30;
            gameSate =true;
        }
        return true;//to have indication when we done
    }

To:

@Override
    public boolean onTouchEvent(MotionEvent event) {
        int action = event.getAction();
        while(action==MotionEvent.ACTION_DOWN){
            spaceY-=3; //y axis location for the bird
            gameSate =true;
        }
        return true;//to have indication when we done
    }

Which didn't work at all, when I changed the onTouchEvent from the if statement to the while loop, the bird was frozen. With the if statement, pressing only make it bounce once, no matter if the screen is being pressed or not

Is there a way to keep the Y axis change smooth while doing it only when action==MotionEvent.ACTION_DOWN

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.