Time for action – declarations for the Sprite class
Add a new class to the project called
Sprite.cs
.Update the class'
using
area to include:using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics;
Add the following declarations to the Sprite class:
public Texture2D Texture; protected List<Rectangle> frames = new List<Rectangle>(); private int frameWidth = 0; private int frameHeight = 0; private int currentFrame; private float frameTime = 0.1f; private float timeForCurrentFrame = 0.0f; private Color tintColor = Color.White; private float rotation = 0.0f; public int CollisionRadius = 0; public int BoundingXPadding = 0; public int BoundingYPadding = 0; protected Vector2 location = Vector2.Zero; protected Vector2 velocity = Vector2.Zero;
What just happened?
All of the animation frames for any individual sprite will be stored on the same sprite sheet, identified by the Texture
variable. The frames
list will hold a single Rectangle
object for each animation frame defined...