Time for action – declarations for the Sprite class
Add a new class file to the project, called
Sprite.vb
.Add the following declarations to the
Sprite
class:Public Texture as Texture2D Protected frames As List(Of Rectangle) = new List(Of Rectangle) Private frameWidth As Integer = 0 Private frameHeight As Integer = 0 Private currentFrame As Integer Private _frameTime As Single = 0.1 Private timeForCurrentFrame As Single = 0.0 Private _tintColor As Color = Color.White Private _rotation As Single = 0.0 Public CollisionRadius As Integer = 0 Public BoundingXPadding As Integer = 0 Public BoundingYPadding As Integer = 0 Protected _location As Vector2 = Vector2.Zero Protected _velocity As Vector2 = 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 for the sprite, while currentFrame
stores the frame...