Game Development Reference
In-Depth Information
With the sub-animation exported, all we have to do to play it back is call the
PlaySubAnim
method of
CIwAnimPlayer
. An example of how to use this function is
as follows:
lpAnimPlayer->PlaySubAnim(0, lpFlagWave, 1.0f,
CIwAnimBlendSource::LOOPING_F, 0.0f);
As you can see, it is almost identical in structure to the
PlayAnim
method. The only
difference is an extra initial parameter, which is the sub-animation index number.
The animation player can support two different sub-animations at the same time
and the index number should be
0
or
1
to indicate which sub-animation you wish
to change.
To detect the current playback status of a sub-animation, we can get hold of the
CIwAnimBlendSource
instance using the
GetSourceSub
method of
CIwAnimPlayer
.
This method takes a single parameter, which is the index number of the sub-
animation required.
Offset animations
When dealing with animations that cause a game character to move, such as
walking, running, or making an attacking move, it is desirable to update the position
of the character with respect to the animation being played so that the character's feet
do not appear to slip on the ground.
Marmalade provides a method of doing this by way of an
offset animation
, which is
an animation that consists of a single bone whose position and rotation can be used
to move an object around the game world. Offset animations are exported using the
same export process as any other animation.
To use an offset animation, we use the
PlayOfsAnim
method of
CIwAnimPlayer
, as
shown in the following code:
lpAnimPlayer->PlayOfsAnim(lpMovementAnim, 1.0f, 0);
The parameters of this function are pointers to the offset animation instance, the
speed of playback (again a value of
1
will play back at normal speed), and the
required animation flags; so it is possible to play back offset animations as one shot
or looped.
To find the current status of the offset animation, we can use the
GetSourceOfs
method on
CIwAnimPlayer
to retrieve the
CIwAnimBlendSource
instance that
maintains it.
Search WWH ::
Custom Search