问题
I am wondering how to use MoveToAction (or any method) for positioning a scene2d Window outside of the stage. I want the menu to slide in and out.
My Stage and my Skin are stored in my world class.
These methods work fine for now, while not at all animating it:
Window window = new Window("NoteBook", world.skin);
...
public void closeBook() {
window.remove();
}
public void openBook() {
world.stage.addActor(window);
}
This is how I am trying to update these functions to allow animation. Here the windows are already added to the stage once during init, so these methods handle only the animation.
public void closeBook() {
MoveToAction action = new MoveToAction();
action.setPosition(-200, -200); // somewhere off screen
action.setDuration(0.5f);
window.addAction(action);
}
public void openBook() {
MoveToAction action = new MoveToAction();
action.setPosition(0, 0); // original location
action.setDuration(0.5f);
window.addAction(action);
}
This seems to partially work, in that it does animate the window's movement, but it stops at the edge of the screen and won't break past it. I've tried adjusting my stage's viewport dimensions but it still always stops at the edge.
So the question is, how do I position a scene2d Window outside (or seemingly outside) of the stage?
回答1:
Try this:
window.setKeepWithinStage(false);
Which should allow the window to move outside of the stage.
来源:https://stackoverflow.com/questions/20021238/libgdx-position-window-outside-of-stage