-
Notifications
You must be signed in to change notification settings - Fork 13
Quickstart
damios edited this page Jan 18, 2021
·
10 revisions
After you have added libgdx-screenmanager as a dependency you can start using it.
There are three simple steps involved in doing so:
- Your game has to extend
ManagedGame. - All screen have to inherit from
ManagedScreen. - Screens and transitions have to be registered with the screen manager before they can be used.
After that, screens can be pushed like this: game.getScreenManager().pushScreen("screen-name", "transition-name"). If no transition should be used, just call pushScreen("screen-name", null).
In practice, this is how a game class could look like:
public class MyGdxGame extends ManagedGame<MyScreenClass, ScreenTransition> {
@Override
public final void create() {
super.create();
// Do some basic stuff
this.batch = new SpriteBatch();
// Add screens
this.screenManager.addScreen("green", new GreenScreen());
this.screenManager.addScreen("blue", new BlueScreen());
// ...
// Add transitions
BlendingScreenTransition blendingTransition = new BlendingScreenTransition(batch, 1F);
screenManager.addScreenTransition("blending_transition", blendingTransition);
// ...
// Push the first screen using a blending transition
this.screenManager.pushScreen("green", "blending_transition");
Gdx.app.debug("Game", "Initialization finished.");
}
}A full example can be found here.
Some other notes:
- Input processors have to be added in a screen via
#addInputProcessor(...). This is required so the input processors of a screen can be automatically registered/unregistered when the screen is shown/hidden. This also means that there is no need to use any InputMultiplexers yourself, as this is all done automatically behind the scenes. - Screens are basically intended as singletons: they are created once and then reused again and again. How a changing state can be handled with this is detailed here.
- ManagedScreens do not need to call
Gdx.gl.glClearColor(0, 0, 0, 0);in theirrender()method. The screen is automatically cleared by the screen manager. To set a specific color, overridegetClearColor(). - If you are planning on using
FrameBuffers inside of a screen, please take a look here.
- Home
- Setup
-
Usage
- Quickstart!
- Screen Lifecycle
- Available transitions
- Technical stuff