X hits on this document

389 views

0 shares

0 downloads

0 comments

73 / 102

   }

   set

   {

       if (value >= sheetSize.X * sheetSize.Y + 1)

       {

           throw new InvalidOperationException(

               "Specified frame index exeeds available frames");

       }

       currentFrame.Y = value / sheetSize.X;

       currentFrame.X = value % sheetSize.X;

   }

}

public bool IsActive { get; private set; }

Let us clarify the meaning of the above properties. The “FrameCount” property simply returns the amount of frames contained in the animation represented by the Animation object. The “Offset” property is used to draw the animation at a specified offset. The “FrameIndex” returns index of the animation’s current frame or sets it. The “IsActive” property can be used to pause the animation by setting it to false.

158.

Add the following constructor to the Animation class:

C#

public Animation(Texture2D frameSheet, Point size,

   Point frameSheetSize)

{

   animatedCharacter = frameSheet;

   frameSize = size;

   sheetSize = frameSheetSize;

   Offset = Vector2.Zero;

}

159.

Add a new method to the Animation class and name it Update. Note that this method is not an override and will need to be explicitly called in order to advance the animation:

C#

public void Update()

{

   if (IsActive)

   {

       if (FrameIndex >= FrameCount - 1)

       {

           IsActive = false;

           FrameIndex = FrameCount - 1; // Stop at last frame

       }

       else

       {

Page | 73

Document info
Document views389
Page views389
Page last viewedMon Jan 23 10:37:35 UTC 2017
Pages102
Paragraphs3115
Words17333

Comments