Game Development Reference
In-Depth Information
Now, add the following method to WorldRenderer :
private void renderGuiFeatherPowerup (SpriteBatch batch) {
float x = -15;
float y = 30;
float timeLeftFeatherPowerup =
worldController.level.bunnyHead.timeLeftFeatherPowerup;
if (timeLeftFeatherPowerup > 0) {
// Start icon fade in/out if the left power-up time
// is less than 4 seconds. The fade interval is set
// to 5 changes per second.
if (timeLeftFeatherPowerup < 4) {
if (((int)(timeLeftFeatherPowerup * 5) % 2) != 0) {
batch.setColor(1, 1, 1, 0.5f);
}
}
batch.draw(Assets.instance.feather.feather,
x, y, 50, 50, 100, 100, 0.35f, -0.35f, 0);
batch.setColor(1, 1, 1, 1);
Assets.instance.fonts.defaultSmall.draw(batch,
"" + (int)timeLeftFeatherPowerup, x + 60, y + 57);
}
}
This method first checks whether there is still time left for the feather power-up effect
to end. Only if this is the case, a feather icon is drawn in the top-left corner under the
gold coin icon. A small number is drawn next to it that displays the rounded time
that is still left until the effect vanishes. There is also some extra code that makes
the feather icon fade back and forth when there are less than four seconds of the
power-up effect to last.
 
Search WWH ::




Custom Search