Time for action – Sprite constructor
Add a constructor to the Sprite class:
public Sprite( Vector2 location, Texture2D texture, Rectangle initialFrame, Vector2 velocity) { this.location = location; Texture = texture; this.velocity = velocity; frames.Add(initialFrame); frameWidth = initialFrame.Width; frameHeight = initialFrame.Height; }
What just happened?
The constructor for the Sprite class directly sets the location
, texture
, and velocity
members to the passed parameter values. It then sets the frameWidth
and frameHeight
variables by extracting that information from the Rectangle
.