Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Animation

Animation component governs a group of animation states to control playback of the states. For convenient, it stores a group of animation clips. Each of those clips would have an associated animation state uniquely created. Animation component is eventful, it dispatch a serials playback status events. See EventType.

Hierarchy

Index

Properties

Protected _clips

_clips: (null | AnimationClip)[] = []

Protected _crossFade

_crossFade: CrossFade = new CrossFade()

Protected _defaultClip

_defaultClip: AnimationClip | null = null

Private _hasBeenPlayed

_hasBeenPlayed: boolean = false

Whether if crossFade() or play() has been called before this component starts.

Protected _nameToState

_nameToState: Record<string, AnimationState> = createMap(true)

playOnLoad

playOnLoad: boolean = false

Whether the default clip should get into playing when this components starts. Note, this field takes no effect if crossFade() or play() has been called before this component starts.

Static EventType

EventType: EnumAlias<typeof EventType> = EventType

Accessors

clips

  • Gets or sets clips this component governs. When set, associated animation state of each existing clip will be stopped. If the existing default clip is not in the set of new clips, default clip will be reset to null.

    Returns (null | AnimationClip)[]

  • Gets or sets clips this component governs. When set, associated animation state of each existing clip will be stopped. If the existing default clip is not in the set of new clips, default clip will be reset to null.

    Parameters

    Returns void

defaultClip

Methods

Protected createState

Protected doCreateState

Private getStateByNameOrDefaultClip

  • getStateByNameOrDefaultClip(name?: undefined | string): any

Private removeStateOfAutomaticClip

Private syncAllowLastFrameEvent

  • _syncAllowLastFrameEvent(): void

Private syncDisallowLastFrameEvent

  • _syncDisallowLastFrameEvent(): void

addClip

createState

  • Creates a state for specified clip. If there is already a clip with same name, the existing animation state will be stopped and overridden.

    Parameters

    • clip: AnimationClip

      The animation clip

    • Optional name: undefined | string

      The animation state name, if absent, the default clip's name will be used

    Returns AnimationState

    The animation state created

crossFade

  • crossFade(name: string, duration?: number): void
  • Smoothly switch to play specified animation state.

    zn

    平滑地切换到指定动画状态。

    Parameters

    • name: string

      The name of the animation to switch to

    • Default value duration: number = 0.3

      The duration of the cross fade, default value is 0.3s

    Returns void

getAnimationState

getState

off

  • off(type: EventType, callback?: undefined | ((...any: any[]) => void), thisArg?: any): void
  • Unregister animation event callback.

    example
    // unregister event to all animation
    animation.off('play', this.onPlay, this);

    Parameters

    • type: EventType

      The event type to unregister

    • Optional callback: undefined | ((...any: any[]) => void)

      The callback to unregister

    • Optional thisArg: any

    Returns void

on

  • on<TFunction>(type: EventType, callback: TFunction, thisArg?: any, once?: undefined | false | true): any
  • Register animation event callback. The event arguments will provide the AnimationState which emit the event. When play an animation, will auto register the event callback to the AnimationState, and unregister the event callback from the AnimationState when animation stopped.

    example
    onPlay: function (type, state) {
        // callback
    }
    // register event to all animation
    animation.on('play', this.onPlay, this);

    Type parameters

    • TFunction: (...any: any[]) => void

    Parameters

    • type: EventType

      The event type to listen to

    • callback: TFunction

      The callback when event triggered

    • Optional thisArg: any
    • Optional once: undefined | false | true

    Returns any

    The registered callback

onDestroy

  • onDestroy(): void

onDisable

  • onDisable(): void

onEnable

  • onEnable(): void

onLoad

  • onLoad(): void

once

  • once<TFunction>(type: EventType, callback: TFunction, thisArg?: any): any

pause

  • pause(): void

play

  • play(name?: undefined | string): void
  • Switch to play specified animation state, without fading.

    Parameters

    • Optional name: undefined | string

      The name of the animation to be played, if absent, the default clip will be played

    Returns void

removeClip

  • removeClip(clip: AnimationClip, force?: undefined | false | true): void
  • Remove clip from the animation list. This will remove the clip and any animation states based on it.
    If there are animation states depend on the clip are playing or clip is defaultClip, it will not delete the clip.
    But if force is true, then will always remove the clip and any animation states based on it. If clip is defaultClip, defaultClip will be reset to null

    deprecated

    please use removeState

    Parameters

    • clip: AnimationClip
    • Optional force: undefined | false | true

      If force is true, then will always remove the clip and any animation states based on it.

    Returns void

removeState

  • removeState(name: string): void

resume

  • resume(): void

start

  • start(): void

stop

  • stop(): void

Generated using TypeDoc