libGDX make touchDown loop until touchUp
libgdx
Solution
You can't "loop" inside an event callback or render callback, as the whole system will stop. One way to get what you want is to set a flag in the `touchDown` method, clear the flag in the `touchUp` method, and then put the "body" of your loop in `render`, guarded by your flag.
boolean touchActive = false;
public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
//start runnable (move player)
touchActive = true;
return true;
}
public void touchUp (InputEvent event, float x, float y, int pointer, int button) {
//stop runnable
touchActive = false;
}
public void render(float delta) {
...
if (touchActive) {
// Do one iteration of your "while" loop
}
...
}
Problem
I'm making game in libGDX. I want to implement game controls, but I have problem with `touchDown` method. touchDown method runs only once. I want to loop in touchDown until touchUp is called. Can someone help me ? ``` class onPlayerGoLeftListener extends InputListener { public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) { //start runnable (move player) return true; } public void touchUp (InputEvent event, float x, float y, int pointer, int button) { //stop runnable } } ``` Thanks p.s. I don't like to use main update method to do this