Creating a Sprite Class
Now you can go ahead and get started on your Sprite base class. What might you want to include in that class?
Table 4-1 lists the members, and Table 4-2 lists the methods.
Table 4-1. Members of your Sprite class
|
Member |
Type |
Description |
|---|---|---|
|
|
|
Sprite or sprite sheet of image being drawn |
|
|
|
Position at which to draw sprite |
|
|
|
Size of each individual frame in sprite sheet |
|
|
|
Offset used to modify frame-size rectangle for collision checks against this sprite |
|
|
|
Index of current frame in sprite sheet |
|
|
|
Number of columns/rows in sprite sheet |
|
|
|
Number of milliseconds since last frame was drawn |
|
|
|
Number of milliseconds to wait between frame changes |
|
|
|
Speed at which sprite will move in both X and Y directions |
Table 4-2. Methods of your Sprite class
|
Method |
Return type |
Description |
|---|---|---|
|
|
|
Sprite constructor method |
|
|
|
Handles all collision checks, movement, user input, and so on |
|
|
|
Draws the sprite |
This chapter will build upon the code that you created in Chapter 3. Open the code from that chapter and add a new class to your project by right-clicking on the project in Solution Explorer and selecting Add → Class. Name the new class file Sprite.cs ...