how to show dialogue without a scene?

Anything libgdx related goes here!

how to show dialogue without a scene?

Postby TruePlayer » Tue Aug 13, 2019 2:13 am

I use my own MVC pattern in which scene2d is not involved. No stage and actors. There is only a world (not from badlogicgames, my own world). Can I show custom dialogs from libGDX?
in all examples that I saw is used scene:
Code: Select all
Skin uiSkin = new Skin(Gdx.files.internal("default_skin/uiskin.json"));
Dialog dialog = new Dialog("Warning", uiSkin, "dialog") {
    public void result(Object obj) {
        System.out.println("result "+obj);
dialog.text("Are you sure you want to yada yada?");
dialog.button("Yes", true); //sends "true" as the result
dialog.button("No", false); //sends "false" as the result;

should I make my world an actor and add it to the stage? or can I do it differently?
Posts: 103
Joined: Sun Jul 28, 2019 12:22 pm

Re: how to show dialogue without a scene?

Postby shatterblast » Tue Aug 13, 2019 6:24 am

Technically, Dialog is still part of Scene2D, and all its visual stuff inherits from Actor. I think you can get close to an MVC pattern, though I personally am not aware of how to in "core". ... ialog.html

The following is a condensed and "simplified" code snippet that can go into render(). It won't have everything, but it should cover most of the basics. The same stuff should roughly apply to Dialog. Take out Table or whatever as works for you.

Code: Select all
        //Loads only once in render().  SpriteBatch will need declaring in create().       
        if ( firstLoad == true) {

            setBattleOrthoCamera( new OrthographicCamera() );
            setBattleExtendViewport( new ExtendViewport( 800, 480, getBattleOrthoCamera() ) );

            setBattlePauseWindowStage()( new Stage(  getBattleExtendViewport(), getBackgroundAnimations_SpriteBatch() ) );


            setInputMultiplexer( new InputMultiplexer() );
            Gdx.input.setInputProcessor( getInputMultiplexer() );
            getInputMultiplexer().addProcessor( getBattleMainStage() );

            int pauseWindow_Width = 350;
            int pauseWindow_Height = 320;

            float pauseWindow_X_Position = (( getBattleExtendViewport().getWorldWidth() - pauseWindow_Width) / 2);
            float pauseWindow_Y_Position = (( getBattleExtendViewport().getWorldHeight() - pauseWindow_Height) / 2);

            pauseWindow = new Window( "Sound Test", skin );
            pauseWindow.setSize( pauseWindow_Width, pauseWindow_Height );
            pauseWindow.setModal( false );
            pauseWindow.setMovable( false );
            pauseWindow.setPosition( pauseWindow_X_Position, pauseWindow_Y_Position );
            pauseWindow.getTitleLabel().setAlignment( );

            narratorTest_TextButton = new TextButton( "Wes Lange's Voice Test", skin );
            narratorTest_Container = new Container( narratorTest_TextButton );

            narratorTest_TextButton.addListener(new ClickListener() {

            public void clicked( InputEvent event, float x, float y ) {

                    narratorTest_TextButton.setDisabled( true );
                    narratorTest_TextButton.setTouchable( Touchable.disabled );
                    narratorTest_Container.addAction( Actions.fadeOut( 2f ) );



            pauseWindow.add( pauseContent_Table = new Table( skin ) ).expand().fillX().fillY();
            pauseContent_Table.align( );
            pauseContent_Table.add( narratorTest_Container );

            getBattlePauseWindowStage().addActor( pauseWindow );

            firstLoad = false;       


        //Back to the normal area of render() that loops each time.

(Edit: Corrected the Stage code.)
Posts: 653
Joined: Sun Jul 06, 2014 1:14 pm

Return to Libgdx

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 1 guest