0
votes

I want to detect touchUp event when user touch my actor(which is call fly), I tried touchDown and it detects it, but touchUp won't get call after releasing finger.

fly.addListener(new InputListener(){
        @Override
        public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
            return super.touchDown(event, x, y, pointer, button);
        }

        @Override
        public void touchUp(InputEvent event, float x, float y, int pointer, int button) {

            super.touchUp(event, x, y, pointer, button);
            System.out.println("touched");
        }

    });

I have already set my inputprocessor to stage. any idea what's wrong ?

1

1 Answers

0
votes

According to the documentation, touchUp will only get fired if the touchDown returned true.

touchUp(InputEvent event, float x, float y, int pointer, int button)

Called when a mouse button or a finger touch goes up anywhere, but only if touchDown previously returned true for the mouse button or touch.

Try

fly.addListener(new InputListener(){
    @Override
    public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
        return true;
    }

    @Override
    public void touchUp(InputEvent event, float x, float y, int pointer, int button) {

        super.touchUp(event, x, y, pointer, button);
        System.out.println("touched");
    }

});