Game Development Reference
In-Depth Information
}
level.mountains.updateScrollPosition
(cameraHelper.getPosition());
if (livesVisual> lives)
livesVisual = Math.max(lives, livesVisual - 1 * deltaTime);
}
We have introduced a new variable livesVisual that will contain pretty much the
same information as lives. However, livesVisual will only decrease slowly over
time whenever the lives are decreased. This enables us to play an animation as long
as livesVisual has not yet reached the current value of lives.
Additionally, add the following import line to the WorldRenderer class:
import com.badlogic.gdx.math.MathUtils;
Next, make the following changes to the same class:
private void renderGuiExtraLive (SpriteBatch batch) {
float x = cameraGUI.viewportWidth - 50
Constants.LIVES_START * 50;
float y = -15;
for (int i = 0; i<Constants.LIVES_START; i++) {
if (worldController.lives<= i)
batch.setColor(0.5f, 0.5f, 0.5f, 0.5f);
batch.draw(Assets.instance.bunny.head,
x + i * 50, y, 50, 50, 120, 100, 0.35f, -0.35f, 0);
batch.setColor(1, 1, 1, 1);
}
if (worldController.lives>= 0
&&worldController.livesVisual>worldController.lives) {
int i = worldController.lives;
float alphaColor = Math.max(0, worldController.livesVisual
- worldController.lives - 0.5f);
float alphaScale = 0.35f * (2 + worldController.lives
- worldController.livesVisual) * 2;
float alphaRotate = -45 * alphaColor;
batch.setColor(1.0f, 0.7f, 0.7f, alphaColor);
batch.draw(Assets.instance.bunny.head,
x + i * 50, y, 50, 50, 120, 100, alphaScale, -alphaScale,
alphaRotate);
batch.setColor(1, 1, 1, 1);
}
}
 
Search WWH ::




Custom Search