2
\$\begingroup\$

I am currently using libgdx. Below codes are added to a stage.

this.addListener(new InputListener() {
        public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
            System.out.println("down");
            return true;
        }

        public void touchUp (InputEvent event, float x, float y, int pointer, int button) {
            System.out.println("up");
        }
        public void touchDragged(InputEvent event, float x, float y , int pointer) {
            System.out.println("dragged");
            zoom(0.01f);
        }
        public boolean scrolled(InputEvent event,
                    float x,
                    float y,
                    int amount) {
            System.out.println("scrolled");
            zoom(0.01f);
            return true;
        }

everything is working just fine (touchUp touchDragged Touchdown) except scrolled. Can someone tell me what is the reason?

-edited for reply comment and answer- On screen class outside stage, I think I already added like screen.set input processor(stage). So touch dragged is working properly and print message 'dragged' and zoom is working. But when I scroll, message 'scrolled' is not printed and zoom function is not called I think. Thank you for comment and answer

\$\endgroup\$
1
  • \$\begingroup\$ What do you mean by "not working" do you mean that the console printing is not occurring? \$\endgroup\$ Commented May 21, 2015 at 23:32

2 Answers 2

2
\$\begingroup\$

The reason why scrolled is not working is...

To activate scrolled in Scene2d, we need this one line

stage.setScrollfocus(actor);

\$\endgroup\$
0
\$\begingroup\$

You need to create an InputProcessor (or an InputMultiplexer) and register this with the LibGdx backend.

You then add your InputListener & Stage to this InputProcessor.

This is a typical use of the function:

Gdx.input.setInputProcessor(inputProcessor);

Read this page for more information https://github.com/libgdx/libgdx/wiki/Event-handling

\$\endgroup\$

You must log in to answer this question.

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