Time for action – Sprite constructor
Add a constructor to the
Sprite
class as follows:Public Sub New( location As Vector2, texture As Texture2D, initialFrame As Rectangle, velocity As Vector2) Me.Texture = texture _location = location _velocity = velocity frames.Add(initialFrame) frameWidth = initialFrame.Width frameHeight = initialFrame.Height End Sub
What just happened?
The constructor for the Sprite
class, sets the Texture
, _location
, and _velocity
members to the passed parameter values, using the Me
notation for Texture
. since its name will otherwise collide with the parameter name. It adds the first frame to the frames list, and then sets the frameWidth
and frameHeight
variables by extracting that information from the Rectangle
.