Time for action – drawing the Sprite
Add the
Draw()
method to theSprite
class:Public Overridable Sub Draw(spriteBatch As SpriteBatch) spriteBatch.Draw( Texture, Center, Source, tintColor, rotation, new Vector2(CSng(frameWidth / 2), CSng(frameHeight / 2)), 1.0, SpriteEffects.None, 0.0) End Sub
What just happened?
The Draw()
method consists of a single call to the SpriteBatch.Draw()
method, using an overload of the method that allows for rotation and scaling.
Because we are specifying a rotation, we need to identify a center point for the rotation to be based around (new Vector2(CSng(frameWidth / 2), CSng(frameHeight / 2))
). Instead of specifying a destination rectangle, we specify a vector that points to the center of the area, the object will occupy on the screen (the Center
property of the Sprite
class).