Animation State

    Animation states are managed by Class AnimationState.

    First get the animation state by getState():

    Then set the speed of the animation to play at:

    The animation state also provides play(), pause(), resume(), stop() methods for playback control, please refer to the play state section below for more details.

    The animation state records the cumulative play time of the animation. Initially, the accumulated play time is 0. As the animation plays naturally, the time will be accumulated. For example, when the animation loops, the cumulative play time will be animation period * 2 just after the second loop.

    • The cumulative play time is obtained from the time field of AnimationState, and can be set explicitly.
    • The progress time is obtained from the field of AnimationState, and is read-only.

    The wrap mode and repeat count of the animation determines the progress time of the animation when it reaches a certain time, whether the cumulative play time is increased by time or changed by direct setting, the progress time will be changed accordingly.

    Animation can be played to the end and stop, or it can be looped all the time, or it can be played to the end and then looped from the end to the beginning, these are collectively called wrap modes and are represented by the enumeration , the following are included:

    In addition, there are reverse looping modes for each of the looping modes in the table above:

    The initial wrap mode of the animation state will be read from the animation clip. When you need to change the wrap mode of the animation state, simply set the wrapMode field of the animation state.

    When the animation wrap mode is:

    • Infinite loop mode: repeatCount will be set to Number.Infinity, i.e. infinite loop.

    Note: setting the repeat count should be done after setting the wrap mode, because resetting the wrap mode will reset the repeat count.

    The animation state provides the following methods to control the play, pause, resume and stop of the animation:

    The playing status of the animation can be queried by the following fields:

    The relationship between the playback control and the playback state is shown in the following figure:

    The animation state allows getting information about all the animations in order to use this information to determine what needs to be done. For more interfaces, please refer to .