0

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.

  • 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](http://www.kilobolt.com/zombie-bird-tutorial-flappy-bird-remake.html) , its a very very nice tutorial, i think all of his methods are very similar to the original. hope it helps :) – Spurdow Aug 14 '14 at 16:23
  • Yes I know for this tutorial, it helped me a lot. Thank you anyway. – user3817453 Aug 14 '14 at 17:57

2 Answers2

2
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);
}
Gabriel Negut
  • 13,860
  • 4
  • 38
  • 45
0

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.

Metaphore
  • 749
  • 1
  • 7
  • 15