Game Development Reference
In-Depth Information
for (int i = 0; i < sliceIndex.size; i++) {
// current slice/column
x = i * sliceWidth;
// vertical displacement using randomized
// list of slice indices
float offsetY = h * (1 + sliceIndex.get(i)
/ (float)sliceIndex.size);
switch (direction) {
case UP:
y = -offsetY + offsetY * alpha;
break;
case DOWN:
y = offsetY - offsetY * alpha;
break;
case UP_DOWN:
if (i % 2 == 0) {
y = -offsetY + offsetY * alpha;
} else {
y = offsetY - offsetY * alpha;
}
break;
}
batch.draw(nextScreen, x, y, 0, 0, sliceWidth, h, 1, 1, 0,
i * sliceWidth, 0, sliceWidth, nextScreen.getHeight(),
false, true);
}
batch.end();
}
}
The effect builds a random list of indices for each slice. The randomization is used
to create a small vertical displacement for the slices so that they arrive at their target
location at different times.
Finally, let the main class of Canyon Bunny use the slice transition effect when the
game is started. Add the following import lines to the CanyonBunnyMain class:
import com.badlogic.gdx.math.Interpolation;
import com.packtpub.libgdx.canyonbunny.screens.transitions
.ScreenTransition;
import com.packtpub.libgdx.canyonbunny.screens.transitions
.ScreenTransitionSlice;
 
Search WWH ::




Custom Search