Game Development Reference
In-Depth Information
if (currScreen != null) currScreen.render(deltaTime);
} else {
// ongoing transition
float duration = 0;
if (screenTransition != null)
duration = screenTransition.getDuration();
// update progress of ongoing transition
t = Math.min(t + deltaTime, duration);
if (screenTransition == null || t >= duration) {
//no transition effect set or transition has just finished
if (currScreen != null) currScreen.hide();
nextScreen.resume();
// enable input for next screen
Gdx.input.setInputProcessor(
nextScreen.getInputProcessor());
// switch screens
currScreen = nextScreen;
nextScreen = null;
screenTransition = null;
} else {
// render screens to FBOs
currFbo.begin();
if (currScreen != null) currScreen.render(deltaTime);
currFbo.end();
nextFbo.begin();
nextScreen.render(deltaTime);
nextFbo.end();
// render transition effect to screen
float alpha = t / duration;
screenTransition.render(batch,
currFbo.getColorBufferTexture(), nextFbo.getColorBufferTexture(),
alpha);
}
}
}
Notice the call to the next screen's render() method to which the delta time of 0 is
passed. This allows the next screen to update its internal state once for initialization
purposes. After this, both screens are paused so that they do not make any progress
in time as long as the transition effect is not finished. Also, the input processor is
set to null to avoid any interference from a potential user input during a running
transition. The desired transition effect, if any, is stored in screenTransition for
future reference. Finally, the t variable is used to keep a track of the effect's elapsed
time and always needs to be reset to 0 to let new transitions start from the beginning.
 
Search WWH ::




Custom Search