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 at 1.0f
, or fully opaque) and a rate of change. The FadingPiece
constructor simply passes the parameters along to the base constructor.
When a FadingPiece
is updated, alphaLevel
is reduced by alphaChangeRate
, making the piece...