Game Development Reference
In-Depth Information
// was picked up during "TransformBack" animation. Otherwise,
// the "TransformBack" animation would be stuck while the
// power-up is still active.
setAnimation(animCopterTransform);
}
timeLeftFeatherPowerup -= deltaTime;
if (timeLeftFeatherPowerup < 0) {
// disable power-up
timeLeftFeatherPowerup = 0;
setFeatherPowerup(false);
setAnimation(animCopterTransformBack);
}
}
dustParticles.update(deltaTime);
// Change animation state according to feather power-up
if (hasFeatherPowerup) {
if (animation == animNormal) {
setAnimation(animCopterTransform);
} else if (animation == animCopterTransform) {
if (animation.isAnimationFinished(stateTime))
setAnimation(animCopterRotate);
}
} else {
if (animation == animCopterRotate) {
if (animation.isAnimationFinished(stateTime))
setAnimation(animCopterTransformBack);
} else if (animation == animCopterTransformBack) {
if (animation.isAnimationFinished(stateTime))
setAnimation(animNormal);
}
}
}
The update() method now contains the logic that is shown in the preceding
diagram. One detail that has not been covered yet is how we can find out if an
animation is finished. The Animation class provides the isAnimationFinished()
method for this purpose. However, this method is only possible if the animation is
played without looping, given the state time.
 
Search WWH ::




Custom Search