Game Development Reference
In-Depth Information
instance.duration = duration;
instance.direction = direction;
instance.slideOut = slideOut;
instance.easing = easing;
return instance;
}
@Override
public float getDuration () {
return duration;
}
}
The second transition effect is implemented in the same way as we did for "fade" as
a singleton class. As you will see in a moment, this class is a little bit heavier because
it not only allows sliding in another screen from the top edge, but also allows you to
slide out the current screen to define the direction of movement. The init() method
allows you to specify all these settings and also takes an interpolation algorithm that
should be used.
Next, add the following code to the same class to implement the render() method of
the ScreenTransition interface:
@Override
public void render (SpriteBatch batch, Texture currScreen,
Texture nextScreen, float alpha) {
float w = currScreen.getWidth();
float h = currScreen.getHeight();
float x = 0;
float y = 0;
if (easing != null) alpha = easing.apply(alpha);
// calculate position offset
switch (direction) {
case LEFT:
x = -w * alpha;
if (!slideOut) x += w;
break;
case RIGHT:
x = w * alpha;
if (!slideOut) x -= w;
break;
case UP:
y = h * alpha;
if (!slideOut) y -= h;
 
Search WWH ::




Custom Search