SetAnimation

From ZDoom Wiki
Jump to navigation Jump to search

Actor

native void SetAnimation(Name animName, double framerate = -1, int startFrame = -1, int loopFrame= -1, int endFrame= -1, int interpolateTics = -1, int flags = 0) (New from 4.12)

Usage

If the calling actor has a 3D model attached, and said model has named animation sequences in it, this function will play the specified animation sequence on the model. Note, currently IQM is the only model format that supports named animation sequences.

This allows for a simple way to play a specific model animation without relying on the tedious process of binding separate key frames to sprite names in MODELDEF. For this to work, the model must include multiple named animation sequences. For example, in Blender they can be created through the use of Nonlinear Animation.

Note: There are several prerequisites in order to be able to use this feature:

1. The actor must have the DECOUPLEDANIMATIONS flag.
2. The model must include multiple named animation sequences.
3. The MODELDEF definition for the model must have the BaseFrame keyword.


Parameters

  • Name animName
The name of the animation sequence to play.
Note: in Blender this is the name of the action (can be seen in the Dope Sheet), not the name of the Nonlinear Animation strip.
  • double framerate
The framerate at which the animation sequence should play. If not specified, the sequence's own framerate will be used.
  • int startFrame
The frame of the animation sequence to start at. By default starts at the beginning.
  • int loopFrame
If specified and the SAF_LOOP flag is used, after the animation has played in full once, it'll keep looping from this frame instead of startFrame.
  • int endFrame
If specified, the model's animation will only play until this frame. Otherwise, will play until the end of the animation.
Note, this argument wasn't initially present when this function was originally added to the engine, but it is present in GZDoom 4.12.
  • int interpolateTics
The number of tics to interpolate between the model's current animation sequence and the new sequence set with animName. A negative value is interpeted as 1 tic.
  • int flags
Multiple flags can be combined with |. The following flags are available:
  • SAF_INSTANT - By default, when setting a new animation, the model will interpolate from its current animation to the new one for the duration set by interpolateTics. This flag disables it.
  • SAF_LOOP - If set, the animation will be looped until a new animation is set. If not set, the sequence will be played from start to end and stop at the final frame.
  • SAF_NOOVERRIDE (New from 4.12.1) - If set, the animation will not start if the same animation is already playing. Mostly intended to be used alongside SAF_LOOP when the function is being repeatedly called with the same animName, so it doesn't get continuously restarted.

Examples

MODELDEF:

Model PulsingThing
{
   Path "models/props"
   Model 0 "pulsingthing.iqm"
   Skin 0 "pulsingthing.png"
   BaseFrame // Decoupled animations REQUIRE this
}

ZScript:

class PulsingThing : Actor
{
  Default
  {
    +DECOUPLEDANIMATIONS
  }
  States
  {
  Spawn:
    // This actor will start the model's 'idlebreathing' animation action
    // as soon as it spawns. Note, the actor's states don't need to
    // animate or progress for this, the function is called once and the
    // model will animate:
    M000 A -1 NoDelay SetAnimation('idlebreathing', flags:SAF_LOOP);
    stop;
  }
}

See also