Game Development Reference
In-Depth Information
int numberOfFrames
¼
GetFrameCount();
_currentFrame
¼
(_currentFrame
þ
1) % numberOfFrames;
}
public int GetCurrentFrame()
{
return _currentFrame;
}
public void Update(double elapsedTime)
{
if (_currentFrame == GetFrameCount() - 1 && Looping == false)
{
Finished
¼
true;
return;
}
_currentFrameTime -= elapsedTime;
if (_currentFrameTime
<
0)
{
AdvanceFrame();
_currentFrameTime
¼
Speed;
UpdateUVs();
}
}
}
This
AnimatedSprite
class works exactly the same as the
Sprite
class,
except for the
AnimatedSprite
class can be told how many frames the texture
has in X and Y dimensions. When the
Update
loop is called, the frame is
changed over time.
This class has quite a few members, but they are mostly used for describing
the animation and tracking its progress. The number of frames in X and Y di-
mension are described by the
_framesX
and
_framesY
member variables.
For the Figure 10.9 example, both these variables would be set to four. The
_currentFrame
variable is the frame that the sprite U,Vs are currently set to.
The
_currentFrameTime
is the amount of time that will be spent on the
current frame before the animation advances to the next frame.
Speed
is a
measure of how much time is spent on each frame in seconds.
Looping
determines if the animation should loop, and
Finished
is a flag that is set to
true once the animation has ended.
Search WWH ::
Custom Search