Game Development Reference
In-Depth Information
public void setScreen (AbstractGameScreen screen,
ScreenTransition screenTransition) {
int w = Gdx.graphics.getWidth();
int h = Gdx.graphics.getHeight();
if (!init) {
currFbo = new FrameBuffer(Format.RGB888, w, h, false);
nextFbo = new FrameBuffer(Format.RGB888, w, h, false);
batch = new SpriteBatch();
init = true;
}
// start new transition
nextScreen = screen;
nextScreen.show(); // activate next screen
nextScreen.resize(w, h);
nextScreen.render(0); // let screen update() once
if (currScreen != null) currScreen.pause();
nextScreen.pause();
Gdx.input.setInputProcessor(null); // disable input
this.screenTransition = screenTransition;
t = 0;
}
}
This new class is meant to work in a similar way to LibGDX's Game class. Therefore,
DirectedGame implements the same interface ( ApplicationListener ) with its
corresponding methods as well as the setScreen() method, which we are already
using to switch our screens. Actually, there are two variants of this method in this
new class: one that allows changing to a new screen with a transition effect and one
without any effect similar to the original screen.
The setScreen() method, which takes an instance of ScreenTransition , initializes
two FBOs for the current and the next screens on its first call. Then, a new transition
is started by storing the next-to-be screen in nextScreen , which in turn is activated
and initialized so that it becomes renderable.
Next, add the following code to the same class to implement the render() method of
the ApplicationListener interface:
@Override
public void render () {
// get delta time and ensure an upper limit of one 60th second
float deltaTime = Math.min(Gdx.graphics.getDeltaTime(),
1.0f / 60.0f);
if (nextScreen == null) {
// no ongoing transition
 
Search WWH ::




Custom Search