I have a main-menu screen with a logo and a bunch of buttons. When the Login-button is pressed, I pop up a dialogue asking for a username and password.

This works fine, other than the "popping up". At the moment the new the dialogue box just shifts everything about, but I'd want to position it over the current scene.

I'm just learning Scene2D.


Dialog is better suited for modal pop-up windows, and it includes a "button" and "content" table already in the window (as the docs say). You can grab these tables with getButtonTable() or getContentTable().

The dialog makes it easy to work with pop up windows. For example, here is a confirmation dialog:

Dialog dialog = new Dialog("Warning", skin, "dialog") {
    public void result(Object obj) {
        System.out.println("result "+obj);
dialog.text("Are you sure you want to quit?");
dialog.button("Yes", true); //sends "true" as the result
dialog.button("No", false);  //sends "false" as the result
dialog.key(Keys.Enter, true); //sends "true" when the ENTER key is pressed

You can use other objects for, say, Yes/No/Cancel options.

  • \$\begingroup\$ Is it possible to have the dialog set its size automatically based on its contents? Looks like it's too small with the example above.. \$\endgroup\$ – Lake Jul 24 '16 at 9:48
  • \$\begingroup\$ I guess it's possible by calling pack() method :) \$\endgroup\$ – Lake Jul 24 '16 at 9:50

Right well, since no one has replied, I will post my solution.

When adding Actors to the Stage, rather than doing:


Which adds a Cell with the given Actor in it, I done the following:


I was then free to overlap actors and move/scale/rotate them via tweening. The only probably I currently see with this is the absolute positioning of Widgets.

In order to position them you have to call:

actor.setPosition(x, y);

So it could be a little difficult when dealing with Android devices of different aspect ratios and resolutions.

  • \$\begingroup\$ absolute position is not so much of a problem as long as you set a static world size and use a viewport with your stage. It'll handle scaling, stretching, and other obscure properites of dealing with aspect ratios and resolutions. \$\endgroup\$ – nhydock Oct 4 '14 at 21:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.