简体   繁体   中英

Inputlistener doesn't handle input on actor

I put the following Table button in my MenuScreen.java file to make a "start game" button:

// register the button "start game"
        TextButton startGameButton = new TextButton( "Start game", getSkin() );
        startGameButton.setTouchable(Touchable.enabled);
        startGameButton.addListener( new InputListener() {

            public boolean touchDown (InputEvent event, float x, float y, int pointer, int button) {
                System.out.println("down");
                Gdx.app.log( HowDrunkAreYou.LOG, "touch d" );
                return true;
        }

            public void touchUp(
                InputEvent event,
                float x,
                float y,
                int pointer,
                int button )
            {
                Gdx.app.log( HowDrunkAreYou.LOG, "touch d" );
                super.touchUp( event, x, y, pointer, button );
                game.getSoundManager().play( HowDrunkAreYouSound.CLICK );
                //game.setScreen( new StartGameScreen( game ) );
            }
        } );
        table.add( startGameButton ).size( 300, 60 ).uniform().spaceBottom( 10 );

For some reason the input handler never fires, java debugger never enters the method. What am I missing? I have tested it on desktop and android, same result.

Neither logcat or console gives me any information about what may be the error.

Thank you!

You need to use Gdx.input.setInputProcessor(stage) in your code. this link will help you. steigert blogspot

Right now all i can tell you is that you need to make a stage, add table to it , and pass stage to setinputprocessor() . for more detail refer this link and you will learn more about stage and using tables

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM