InputListener touchDown - Not able to jump while running

Anything libgdx related goes here!

InputListener touchDown - Not able to jump while running

Postby BoBNet » Thu May 02, 2019 8:38 pm

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.

Any help appreciated.

Code: Select all
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();
                } 
BoBNet
 
Posts: 2
Joined: Thu May 02, 2019 8:23 pm

Re: InputListener touchDown - Not able to jump while runnin

Postby shatterblast » Fri May 03, 2019 1:47 am

I am not sure if using LWJGL3 will fix your issue, but you might try that approach first, replacing LWJGL2. Are you preferring keyboard or joystick as your input device? I think joysticks tend to handle multiple button pushes at once much better.
shatterblast
 
Posts: 404
Joined: Sun Jul 06, 2014 1:14 pm

Re: InputListener touchDown - Not able to jump while runnin

Postby BoBNet » Fri May 03, 2019 3:49 am

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.
BoBNet
 
Posts: 2
Joined: Thu May 02, 2019 8:23 pm

Re: InputListener touchDown - Not able to jump while runnin

Postby shatterblast » Fri May 03, 2019 4:07 am

Have you considered adding "on screen controls"? It involves the concept of putting directional controls on the screen. You could notify the user of available input options.
shatterblast
 
Posts: 404
Joined: Sun Jul 06, 2014 1:14 pm


Return to Libgdx

Who is online

Users browsing this forum: No registered users and 1 guest