0
votes

So, I am developing a flappy bird clone. I created a button which bounces the bird. What I also want for this button is to draw something (totally irrelevant at this point). But not each time the button is hit. I already tried this with:

if (Gdx.input.isTouched()) {
        batcher.draw(birdRed, bird.getX(), bird.getY(),
        bird.getWidth() / 2.0f, bird.getHeight() / 2.0f,
        bird.getWidth(), bird.getHeight(), 1, 1, 1);
    }

But this is now what I want. I want specifically to draw something when button is hit first time. I hope you understand my problem. Thanks for your help.

2
to save you from all troubles and i know this might not be the answer your looking for but theres a great tutorial for flappy bird clone from kilobolt here , its a very very nice tutorial, i think all of his methods are very similar to the original. hope it helps :)Spurdow
Yes I know for this tutorial, it helped me a lot. Thank you anyway.user3817453

2 Answers

2
votes
boolean touched = false;

...

if (Gdx.input.isTouched() && !touched) {
    touched = true;
    batcher.draw(birdRed, bird.getX(), bird.getY(),
    bird.getWidth() / 2.0f, bird.getHeight() / 2.0f,
    bird.getWidth(), bird.getHeight(), 1, 1, 1);
}
0
votes

If you use button actor then you can handle change event and use some boolean flag to keep it's first time pressed state.

private boolean wasPressed = false;

Somewhere in button initialization code:

Button pushBirdButton = new Button();
pushBirdButton.addListener(new ChangeListener() {
    @Override
    public void changed(ChangeEvent event, Actor actor) {
        wasPressed = true;
    }
});

And then you can always check was you button pressed or not.