Time for action – fading pieces
- Add a new class to the Flood Control project called "FadingPiece".
- Add
using Microsoft.Xna.Framework;
to theusing
area at the top of the class. - Update the declaration of the class to read
class FadingPiece : GamePiece
- Add the following declarations to the FadingPiece class:
public float alphaLevel = 1.0f; public static float alphaChangeRate = 0.02f;
- Add a constructor for the FadingPiece class:
public FadingPiece(string pieceType, string suffix) : base(pieceType, suffix) { }
- Add a method to update the piece:
public void UpdatePiece() { alphaLevel = MathHelper.Max( 0, alphaLevel - alphaChangeRate); }
What just happened?
The simplest of our animated pieces, the FadingPiece
only requires an alpha value (which always starts ...
Get XNA 4.0 Game Development by Example Beginner's Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.