Question

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!

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top