简体   繁体   中英

How to fit a Scene2d window to it's content ? ( Libgdx )

All is on the title , I've tried to follow step by step the example provided by Nathan Sweet ( Libgdx main contributor ) to create a window in Scene2d but I come up with an unexpected result :

在此处输入图片说明

Like you can see the text gose out the window , here is my code for the window :

Window window = new Window("The new Window commIng up", skin_deff);
               window.setPosition(400, 200);    
               window.pack();


        // putting  stuff together

                table.debug();
                table.add(heading).colspan(3).expandX().spaceBottom(50).row();;
                table.add(scrollPane).uniformX().expandY().top().left();
                table.add(window).padLeft(30);
                // table.add(play).uniformX();
                table.add(back).uniformX().bottom().right().padLeft(550);
                stage.addActor(table);

This is the example of Nathan Sweet that I'm trying to follow :

在此处输入图片说明

Code :

label.setPosition(100, 200);
        stage.addActor(label);

        Window window = new Window("[RED]Multicolor Bla Bla Bla[GREEN] Title", skin);
        window.setPosition(400, 200);
        window.pack();
        stage.addActor(window);

I've found the solution , the issue was in my table layout :

                table.debug();

                table.add(heading).colspan(3).expandX().spaceBottom(50).row();
                table.add(scrollPane).uniformX().expandY().top().left();
                table.add(window).top();
                // table.add(play).uniformX();
                table.add(back).uniformX().bottom().right();

                stage.addActor(table);

Instead of

            table.debug();
            table.add(heading).colspan(3).expandX().spaceBottom(50).row();;
            table.add(scrollPane).uniformX().expandY().top().left();
            table.add(window).padLeft(30);
            // table.add(play).uniformX();
            table.add(back).uniformX().bottom().right().padLeft(550);
            stage.addActor(table);

The padLeft applied to the window and the back button was forcing the text to overlap the window .

And now the result looks much better :) :

在此处输入图片说明

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