Game Development Reference
In-Depth Information
The constructor of the AnimatedSprite sets some default values. A freshly
created sprite doesn't loop, and has its Finished flag set to false, its frame
speed set to about 30 frames per second, and the _ currentFrameTime is set to
0.03 seconds, which will make the animation run at 30 frames per second.
The GetIndexFromFrame method takes an index as shown in Figure 10.10
and returns an X,Y coordinate of the index position. For example, index 0 would
return 0,0 and index 15 would return 3,3. The index number is broken into an
X and Y coordinate by dividing the index by the row length; this gives the
number of rows and therefore the Y coordinate of the index. The X coordinate is
then whatever is left of the index when the Y rows are removed. This function is
very useful when translating, calculating the U,Vs for a certain frame.
UpdateUVs uses the current frame index to change the U,Vs so the sprite
correctly represents that frame. It first gets the X,Y coordinates of the current
frame using GetIndexFromFrame . Then it calculates the width and height of
Figure 10.10
Animated explosion texture map with frame index.
 
Search WWH ::




Custom Search