Using InputListener attached to images for touchscreen control I initially had the problem of the player being able to continuously jump and fix themselves to the top of the screen by simply holding the jump button.

This was resolved by adding a gdx.input.justTouched() check before calling the jump() method. However, this annoyingly then introduced a new issue of not being able to jump whilst holding a direction button. The direction button first has to be released before the jump will function.

if (player.presentState != Player.State.DEAD && player.presentState != Player.State.WIN) {
            if (controller.isRightPressed() && player.body.getLinearVelocity().x <= 1.75)
                player.body.applyLinearImpulse(new Vector2(0.1f, 0), player.body.getWorldCenter(), true);
            if (controller.isLeftPressed() && player.body.getLinearVelocity().x >= -1.75)
                player.body.applyLinearImpulse(new Vector2(-0.1f, 0), player.body.getWorldCenter(), true);
            if (controller.isUpPressed() && controller.isJumpPressed() && player.presentState != Player.State.FALLING)
                if (Gdx.input.justTouched()){
            if (controller.isDownPressed()){
            if (controller.isJumpPressed() && player.presentState != Player.State.JUMPING){
                if (Gdx.input.justTouched()) {

The jump() method operates under two different state conditions.

If the player is state.ground or state.running, a positive y-impulse is applied.

If the player is state.falling a slight positive y-impulse is applied with linearDampening allowing the player to control the descent as to float/glide down.

This all works perfectly via my keyboard input implementation but not in my touchscreen one.

How to resolve this?

  • 1
    \$\begingroup\$ Traditionally, to allow a player to jump againg, a flag that tells if the player has touched the ground is checked. It is set to true when they land, and set to false when they jump, making it not possible to multiple-jump. \$\endgroup\$ – Vaillancourt May 3 '19 at 1:05
  • \$\begingroup\$ I actually need to be able to use the jump button to control the players descent so as to float/glide down. My keyboard input implementation works perfect, its just the touch screen. \$\endgroup\$ – BoB May 3 '19 at 3:42

You're probably aware, but justTouched() isn't working for you on mobile because another finger is already touching the screen when jump is pressed, causing it to evaluate to false.

I'd look into using touchDown(x, y, pointer, button) from InputProcessor. It is called once per new touch, not just for the first. Add an if statement to it that checks if x&y are on your jump button along with player.presentState != Player.State.JUMPING, then execute player.jump() if both hold true!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.