LibGDX makes touchDown loop until touchUp

I am making a game in libGDX.

I want to implement game controls, but I have a problem with the method touchDown. The touchDown method is executed only once. I want to contact the connector until touchUp is called. Can anybody 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
    }

}

thank

ps I do not like to use the main update method for this

+3
source share
2 answers

"" , . , , - touchDown, touchUp, "" render, .

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
   }
   ...
}
+9

render()

 if (Gdx.input.isTouched()){
  //some thing move()
}
0

All Articles