Time for action – adding animation frames

  1. Add the AddFrame() method to the Sprite class:
    public void AddFrame(Rectangle frameRectangle)
    {
        frames.Add(frameRectangle);
    }

What just happened?

Adding a frame to the sprite's animation is as simple as adding the corresponding Rectangle to the frames list. When the animation is updated, the frame value will be compared to the number of entries in frames (via frames.Count) eliminating the need to store the number of animation frames as a separate value.

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.