X hits on this document

293 views

0 shares

0 downloads

0 comments

72 / 102

152.

Compile and deploy the project. The game should now be completely playable, though severely lacking in polish. Having left some placeholders to support the addition of animations, the catapults will actually disappear during various stages of the game. In our next task, we will add sounds and animations to improve the game experience.

Task 3 – Polishing the game – Sounds and animations

While the game is fully playable in its current state, the game experience is lessened by the lacking presentation. In this task, we will improve the game’s presentation by incorporating sound and animation.

153.

Create a new project folder under the “CatapultGame” project and name it Utility.

154.

Create a new class under the “Utility” project folder and name it Animation.

155.

Add the following using statements to the beginning of the new class file:

C#

using Microsoft.Xna.Framework;

using Microsoft.Xna.Framework.Graphics;

Note: Remember to keep setting the namespace for new classes to “CatapultGame”.

156.

Add the following fields to the Animation class:

C#

// Animation variables

Texture2D animatedCharacter;

Point sheetSize;     

public Point currentFrame;

public Point frameSize;

The above fields will allow the animation class to save a texture which serves as the animation strip and will also allow tracking of the animation’s dimensions and state.

157.

Add the following properties to the Animation class:

C#

public int FrameCount

{

   get { return sheetSize.X * sheetSize.Y; }

}

public Vector2 Offset { get; set; }

public int FrameIndex

{

   get

   {

       return sheetSize.X * currentFrame.Y + currentFrame.X;

Page | 72

Document info
Document views293
Page views293
Page last viewedSat Dec 10 22:57:03 UTC 2016
Pages102
Paragraphs3115
Words17333

Comments