# Using InputListener touchDown - Unable to jump while pressing direction button

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()){
player.superJump();
}
if (controller.isDownPressed()){
player.dive();
}
if (controller.isJumpPressed() && player.presentState != Player.State.JUMPING){
if (Gdx.input.justTouched()) {
player.jump();
}


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?

• 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. – Vaillancourt May 3 '19 at 1:05
• 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. – BoB May 3 '19 at 3:42