- XNA 4.0 Game Development by Example Beginner's Guide(Visual Basic Edition)
- Kurt Jaegers
- 182字
- 2021-08-20 15:50:42
Animated pieces
We will define three different types of animated pieces: rotating, falling, and fading. The animation for each of these types will be accomplished by altering the parameters of the SpriteBatch.Draw()
call.
Classes for animated pieces
In order to represent the three types of animated pieces, we will create three new classes. Each of these classes will inherit from the GamePiece
class, meaning they will contain all of the methods and members of the GamePiece
class but will add additional information to support the animation.
Tip
Child classes
Child classes inherit all of their parent's members and methods. The RotatingPiece
class can refer to the _pieceType
and _pieceSuffix
of the piece, without recreating them within RotatingPiece
itself. Additionally, child classes can extend the functionality of their base class, adding new methods and properties, or overriding old ones. In fact, Game1
itself is a child of the Micrsoft.Xna.Game
class, which is why all of the methods we use (Update()
, Draw()
, LoadContent()
, and so on) are declared with the Overrides
modifier.
Let's begin by creating the class we will use for rotating pieces.