Time for action – fading pieces

  1. Add a new class to the Flood Control project called "FadingPiece".
  2. Add using Microsoft.Xna.Framework; to the using area at the top of the class.
  3. Update the declaration of the class to read class FadingPiece : GamePiece
  4. Add the following declarations to the FadingPiece class:
    public float alphaLevel = 1.0f;
    public static float alphaChangeRate = 0.02f;
  5. Add a constructor for the FadingPiece class:
    public FadingPiece(string pieceType, string suffix)
        : base(pieceType, suffix)
    {
    
    }
    
  6. 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.