Game Development Reference
In-Depth Information
break;
case DOWN:
y = -h * alpha;
if (!slideOut) y += h;
break;
}
// drawing order depends on slide type ('in' or 'out')
Texture texBottom = slideOut ? nextScreen : currScreen;
Texture texTop = slideOut ? currScreen : nextScreen;
// finally, draw both screens
Gdx.gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
batch.draw(texBottom, 0, 0, 0, 0, w, h, 1, 1, 0, 0, 0,
currScreen.getWidth(), currScreen.getHeight(),
false, true);
batch.draw(texTop, x, y, 0, 0, w, h, 1, 1, 0, 0, 0,
nextScreen.getWidth(), nextScreen.getHeight(),
false, true);
batch.end();
}
The
render()
method of this transition effect calculates the drawing order and
position offsets for the current and the next screens using the
direction
,
slideOut
,
and
alpha
variables. The value in
alpha
might be altered before it is used for
calculations if an interpolation algorithm is set.
Finally, let the game screen use the slide transition effect when it wants to go back to
the menu screen. Add the following import lines to the
WorldController
class:
import com.badlogic.gdx.math.Interpolation;
import com.packtpub.libgdx.canyonbunny.screens.transitions
.ScreenTransition;
import com.packtpub.libgdx.canyonbunny.screens.transitions
.ScreenTransitionSlide;
After this, make the following changes to the same class:
private void backToMenu () {
// switch to menu screen
ScreenTransition transition = ScreenTransitionSlide.init(0.75f,