T
T
Tahath2015-03-27 17:48:43
Game development
Tahath, 2015-03-27 17:48:43

LibGdx image switching, how best to implement?

Hello, I'm new and have been learning Java and libGdx for about a month. I set myself the task of writing code in libGdx. The bottom line is that when you touch the phone screen (or click the mouse in the window), the current picture is replaced by the next one, and the background music changes. I tried to implement changing pictures via TouchDown -> a++ but it doesn't work because TouchDown gives out 2 - 4 or more numbers and the pictures change too fast. Please tell me how best to implement the idea, if possible, with extended comments on each step, because in most tutorials the data is presented in pieces and putting everything together is not enough. Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DKpix, 2015-03-28
@Tahath

I will say right away: do not trust my answer too much. I am also not a programmer and just learning libgdx.
So. In order:
As I did... There is an InputHandler class that implements the InputProcessor interface. At the start of the game, I instantiate it and pass it to Gdx.input.setInputProcessor. Moreover, in my case, the touchDown method is called once when clicked, no matter how long the click was. You, as I understand it, if the button is pressed, the method is called every iteration of the game loop. As if you wrote somewhere in the middle of this loop something like "if (Gdx.input.isButtonPressed(Input.Buttons.LEFT)) a++;" (by the way, if you replace this method with Gdx.input.justTouched(), everything will be as it should and without a processor).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question