0
\$\begingroup\$

I'm using libGdx to create a simple platformer.

I used a set of images as an onScreen controller for Android, and use this code to fire a shot ->

        @Override
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            downPressed = true;
            return true;
            //return super.touchDown(event, x, y, pointer, button);
        }

        @Override
        public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
            downPressed = false;
            //super.touchUp(event, x, y, pointer, button);
        }

But when I keep the button pressed, the player continues to shoot which I don't want, I want the player to tap-to-shoot.

What am I doing wrong?

\$\endgroup\$

2 Answers 2

1
\$\begingroup\$

The reason why the player continues to shoot is once you press the button downPress=true. It will stay true until you release the button. You could just call the shoot method from the touchDown event.

        @Override
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            downPressed = true;
            ShootNow();
            return true;
            //return super.touchDown(event, x, y, pointer, button);
        }

        @Override
        public void touchUp(InputEvent event, float x, float y, int pointer, int button) {
            downPressed = false;
            //super.touchUp(event, x, y, pointer, button);
        }
\$\endgroup\$
0
\$\begingroup\$

You could use Gdx.input.justTouched() in your input loop to check for a tap event, then check if the Gdx.input.getX() and .getY() coordinates are within the bounds of any of your 'controller' images and respond accordingly.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .