2

I am coding a little game with libgdx for android mobile devices, and I am stuck with a button. (It is a TextButton) I want to move an object continuosly, while that button is pressed.

newGameButton.addListener(new InputListener() {
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            object.x += 200 * Gdx.graphics.getDeltaTime();
            return false;
        }
    });

My problem is, the object moves only one frame (because the button is pressed only once), but I want it to move as long as the button is held down. I also tried it with switching a boolean variable from FALSE to TRUE every time that listener sends a "down" signal, but it still does not get me more than one frame of movement.

I figured out, in the

@Override
public void render() {...}

method, there is a Gdx.input.isButtonPressed() method, but that one only seems to work for mousebuttons.

I think I read almost any tutorial and help page, but I still can't figure this out. The solution is quite simple I guess, since most answers to similiar topics refer to the touchDown method.

Any help is much appreciated!

Wolfgang Deigele
  • 85
  • 1
  • 1
  • 7

0 Answers0