Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Skeleton

The skeleton of Spine

(Skeleton has a reference to a SkeletonData and stores the state for skeleton instance, which consists of the current pose's bone SRT, slot colors, and which slot attachments are visible.
Multiple skeletons can use the same SkeletonData which includes all animations, skins, and attachments.)

Hierarchy

Index

Constructors

Properties

Accessors

Methods

Constructors

constructor

Properties

Private __prefab

__prefab: CompPrefabInfo | null = null

Protected _accTime

_accTime: number = 0

Protected _animationName

_animationName: string = ""

Protected _animationQueue

_animationQueue: AnimationItem[] = []

Protected _assembler

_assembler: IAssembler | null = null

Protected _blendHash

_blendHash: number = 0

Protected _blendState

_blendState: BlendState = new BlendState()

Protected _cacheMode

_cacheMode: AnimationCacheMode = AnimationCacheMode.REALTIME

Protected _cachedSockets

_cachedSockets: Map<string, number> = new Map<string, number>()

Optional _clipper

_clipper: spine.SkeletonClipping

Protected _color

_color: Color = Color.WHITE.clone()

_curFrame

_curFrame: AnimationFrame | null = null

Protected _customMaterial

_customMaterial: Material | null = null

Protected _debugBones

_debugBones: boolean = false

Protected _debugMesh

_debugMesh: boolean = false

_debugRenderer

_debugRenderer: Graphics | null

Protected _debugSlots

_debugSlots: boolean = false

Protected _defaultCacheMode

_defaultCacheMode: AnimationCacheMode = AnimationCacheMode.REALTIME

Protected _delegateSrc

_delegateSrc: Node | null = null

Protected _dstBlendFactor

_dstBlendFactor: BlendFactor = BlendFactor.ONE_MINUS_SRC_ALPHA

_effectDelegate

_effectDelegate: VertexEffectDelegate | null | undefined = null

Private _enabled

_enabled: boolean = true

_endEntry

_endEntry: any

_endSlotIndex

_endSlotIndex: any

Protected _enumAnimations

_enumAnimations: any = Enum({})

Protected _enumSkins

_enumSkins: any = Enum({})

_frameCache

_frameCache: AnimationCache | null = null

Protected _headAniInfo

_headAniInfo: AnimationItem | null = null

Private _id

_id: string = idGenerator.getNewId()

For internal usage.

Protected _instanceMaterialType

_instanceMaterialType: InstanceMaterialType = InstanceMaterialType.ADD_COLOR_AND_TEXTURE

Protected _isAniComplete

_isAniComplete: boolean = true

Protected _lastParent

_lastParent: Node | null = null

Protected _listener

_listener: AnimationStateListener | null

Protected materialCache

materialCache: {} = {} as any

Type declaration

Protected _materialInstances

_materialInstances: (null | MaterialInstance)[] = []

Protected _materials

_materials: (null | Material)[] = []

Protected _meshRenderDataArray

_meshRenderDataArray: SkeletonMeshData[] = []

_meshRenderDataArrayIdx

_meshRenderDataArrayIdx: number = 0

Protected _models

_models: Model[] = []

Protected _name

_name: string

_objFlags

_objFlags: number

Protected _playCount

_playCount: number = 0

Protected _playTimes

_playTimes: number = 0

Protected _postAssembler

_postAssembler: IAssembler | null = null

Protected _preCacheMode

_preCacheMode: number = -1

Private _premultipliedAlpha

_premultipliedAlpha: boolean = true

Indicates whether to enable premultiplied alpha. You should disable this option when image's transparent area appears to have opaque pixels, or enable this option when image's half transparent area appears to be darken.

Protected _renderData

_renderData: RenderData | null = null

Protected _renderDataFlag

_renderDataFlag: boolean = true

Protected _renderFlag

_renderFlag: boolean = true

Protected _rootBone

_rootBone: Bone | null

Private sceneGetter

sceneGetter: null | (() => RenderScene) = null

_skeleton

_skeleton: Skeleton | null

Protected _skeletonCache

_skeletonCache: SkeletonCache | null = null

Protected _skeletonData

_skeletonData: SkeletonData | null = null

Protected _socketNodes

_socketNodes: Map<number, Node> = new Map()

Protected _sockets

_sockets: SpineSocket[] = []

Protected _srcBlendFactor

_srcBlendFactor: BlendFactor = BlendFactor.SRC_ALPHA

_startEntry

_startEntry: any

_startSlotIndex

_startSlotIndex: any

Protected Optional _state

_state: spine.AnimationState

Private _timeScale

_timeScale: number = 1

The time scale of this skeleton.

Protected _useTint

_useTint: boolean = false

Protected _visFlags

_visFlags: number = Layers.Enum.NONE

attachUtil

attachUtil: AttachUtil

Protected defaultAnimation

defaultAnimation: string = ""

The name of default animation.

property

{String} defaultAnimation

Protected defaultSkin

defaultSkin: string = ""

The name of default skin.

property

{String} defaultSkin

enableBatch

enableBatch: boolean = false

Enabled batch model, if skeleton is complex, do not enable batch, or will lower performance.

loop

loop: boolean = true

TODO

node

node: Node = NullNode

The node this component is attached to. A component is always attached to a node.

example
import { log } from 'cc';
log(comp.node);

paused

paused: boolean = false

The skeletal animation is paused?

property

paused

readonly
default

false

stencilStage

stencilStage: Stage = Stage.DISABLED

The component stencil stage (please do not any modification directly on this object)

Static AnimationCacheMode

AnimationCacheMode: AnimationCacheMode = AnimationCacheMode

Static Assembler

Assembler: IAssemblerManager | null = null

The render data assembler

Static BlendState

BlendState: BlendFactor = BlendFactor

The blend factor enums

see

BlendFactor

Static PostAssembler

PostAssembler: IAssemblerManager | null = null

The post render data assembler

Static SpineSocket

SpineSocket: SpineSocket = SpineSocket

Static system

system: null = null

Accessors

scriptAsset

  • get scriptAsset(): null

animationIndex

  • get animationIndex(): number
  • set animationIndex(value: number): void

defaultSkinIndex

  • get defaultSkinIndex(): number
  • set defaultSkinIndex(value: number): void

isOnLoadCalled

  • get isOnLoadCalled(): number

animation

  • get animation(): string
  • set animation(value: string): void

blendHash

  • get blendHash(): number

color

  • get color(): Readonly<Color>
  • set color(value: {}): void

customMaterial

  • get customMaterial(): null | Material
  • set customMaterial(val: null | Material): void

debugBones

  • get debugBones(): boolean
  • set debugBones(v: boolean): void

debugMesh

  • get debugMesh(): boolean
  • set debugMesh(value: boolean): void

debugSlots

  • get debugSlots(): boolean
  • set debugSlots(v: boolean): void

defaultCacheMode

delegateSrc

  • set delegateSrc(value: Node): void

dstBlendFactor

enabled

  • get enabled(): boolean
  • set enabled(value: boolean): void

enabledInHierarchy

  • get enabledInHierarchy(): boolean

isValid

  • get isValid(): boolean
  • Indicates whether the object is not yet destroyed. (It will not be available after being destroyed)
    When an object's destroy is called, it is actually destroyed after the end of this frame. So isValid will return false from the next frame, while isValid in the current frame will still be true. If you want to determine whether the current frame has called destroy, use isValid(obj, true), but this is often caused by a particular logical requirements, which is not normally required.

    default

    true

    readonly
    example
    import { Node, log } from 'cc';
    const node = new Node();
    log(node.isValid);    // true
    node.destroy();
    log(node.isValid);    // true, still valid in this frame
    // after a frame...
    log(node.isValid);    // false, destroyed in the end of last frame

    Returns boolean

material

materials

meshRenderDataArray

name

  • get name(): string
  • set name(value: string): void

premultipliedAlpha

  • get premultipliedAlpha(): boolean
  • set premultipliedAlpha(v: boolean): void

renderData

  • get renderData(): null | RenderData

sharedMaterial

sharedMaterials

  • get sharedMaterials(): (null | Material)[]
  • set sharedMaterials(val: (null | Material)[]): void

skeletonData

  • dstBlendFactor

    The skeleton data contains the skeleton information (bind pose bones, slots, draw order, attachments, skins, etc) and animations but does not hold any state.
    Multiple skeletons can share the same skeleton data.

    property

    {sp.SkeletonData} skeletonData

    Returns SkeletonData

  • dstBlendFactor

    The skeleton data contains the skeleton information (bind pose bones, slots, draw order, attachments, skins, etc) and animations but does not hold any state.
    Multiple skeletons can share the same skeleton data.

    property

    {sp.SkeletonData} skeletonData

    Parameters

    Returns void

socketNodes

  • get socketNodes(): Map<number, Node>

sockets

  • The bone sockets this animation component maintains.
    Sockets have to be registered here before attaching custom nodes to animated bones.

    Returns SpineSocket[]

  • The bone sockets this animation component maintains.
    Sockets have to be registered here before attaching custom nodes to animated bones.

    Parameters

    Returns void

srcBlendFactor

timeScale

  • get timeScale(): number
  • set timeScale(value: number): void

useTint

  • get useTint(): boolean
  • set useTint(value: boolean): void

uuid

  • get uuid(): string

visibility

  • get visibility(): number
  • set visibility(val: number): void

Methods

preload

  • __preload(): void

Protected attachToScene

  • _attachToScene(): void

Protected canRender

  • _canRender(): boolean

Protected checkAndUpdateRenderData

  • _checkAndUpdateRenderData(): void

Private cleanMaterialCache

  • _cleanMaterialCache(): void

Protected clearMaterials

  • _clearMaterials(): void

collectModels

  • _collectModels(): Model[]

destroyImmediate

  • _destroyImmediate(): void

destruct

  • _destruct(): void
  • Clear all references in the instance.

    NOTE: this method will not clear the getter or setter functions which defined in the instance of CCObject. You can override the _destruct method if you need, for example: _destruct: function () { for (var key in this) { if (this.hasOwnProperty(key)) { switch (typeof this[key]) { case 'string': this[key] = ''; break; case 'object': case 'function': this[key] = null; break; } } }

    Returns void

Protected detachFromScene

  • _detachFromScene(): void

Protected emitCacheCompleteEvent

  • _emitCacheCompleteEvent(): void

Protected ensureListener

  • _ensureListener(): void

Protected flushAssembler

  • _flushAssembler(): void

Optional Private getLocalBounds

  • getLocalBounds(out_rect: Rect): void
  • If the component's bounding box is different from the node's, you can implement this method to supply a custom axis aligned bounding box (AABB), so the editor's scene view can perform hit test properly.

    Parameters

    • out_rect: Rect

      The rect to store the result bounding rect

    Returns void

Private getRenderScene

  • _getRenderScene(): RenderScene

Protected indexBoneSockets

  • _indexBoneSockets(): void

instantiate

  • instantiate(cloned: any): any

Protected nodeStateChange

offSyncTransform

  • _offSyncTransform(): void

Protected onMaterialModified

  • onMaterialModified(index: number, material: Material | null): void

onPreDestroy

  • _onPreDestroy(): void

Protected onRebuildPSO

  • onRebuildPSO(index: number, material: Material | null): void

onSyncTransform

  • _onSyncTransform(): void

Protected onVisibilityChange

  • onVisibilityChange(val: any): void

Protected postCanRender

  • _postCanRender(): void

Protected postRender

  • postRender(render: Batcher2D): void

Protected refreshInspector

  • _refreshInspector(): void

Protected render

  • render(ui: Batcher2D): void

Protected updateAnimEnum

  • _updateAnimEnum(): void

Protected updateBatch

  • _updateBatch(): void

updateBlendFunc

  • _updateBlendFunc(): void

Protected updateCache

  • updateCache(dt: number): void

Protected updateColor

  • _updateColor(): void

Protected updateDebugDraw

  • _updateDebugDraw(): void

Protected updateRealtime

  • updateRealtime(dt: number): void

Protected updateSkeletonData

  • _updateSkeletonData(): void

Protected updateSkinEnum

  • _updateSkinEnum(): void

Protected updateSocketBindings

  • _updateSocketBindings(): void

Protected updateUseTint

  • _updateUseTint(): void

Protected validateRender

  • _validateRender(): void

Private verifySockets

addAnimation

  • addAnimation(trackIndex: number, name: string, loop: boolean, delay?: undefined | number): undefined | null | TrackEntry
  • Adds an animation to be played delay seconds after the current or last queued animation.
    Returns a {{#crossLinkModule "sp.spine"}}sp.spine{{/crossLinkModule}}.TrackEntry object.

    method

    addAnimation

    Parameters

    • trackIndex: number
    • name: string
    • loop: boolean
    • Optional delay: undefined | number

    Returns undefined | null | TrackEntry

addComponent

  • addComponent<T>(classConstructor: Constructor<T>): T | null
  • addComponent(className: string): Component | null

clearTrack

  • clearTrack(trackIndex: number): void
  • Clears track of animation state by trackIndex.

    method

    clearTrack

    Parameters

    • trackIndex: number

    Returns void

clearTracks

  • clearTracks(): void

destroy

  • destroy(): boolean

destroyRenderData

  • destroyRenderData(): void

disableRender

  • disableRender(): void

findAnimation

  • findAnimation(name: string): null | Animation
  • Find animation with specified name.

    method

    findAnimation

    Parameters

    • name: string

    Returns null | Animation

findBone

  • findBone(boneName: string): null | Bone
  • Finds a bone by name. This does a string comparison for every bone.
    Returns a {{#crossLinkModule "sp.spine"}}sp.spine{{/crossLinkModule}}.Bone object.

    method

    findBone

    Parameters

    • boneName: string

    Returns null | Bone

findSlot

  • findSlot(slotName: string): null | Slot
  • Finds a slot by name. This does a string comparison for every slot.
    Returns a {{#crossLinkModule "sp.spine"}}sp.spine{{/crossLinkModule}}.Slot object.

    method

    findSlot

    Parameters

    • slotName: string

    Returns null | Slot

getAttachment

  • getAttachment(slotName: string, attachmentName: string): null | Attachment
  • Returns the attachment for the slot and attachment name. The skeleton looks first in its skin, then in the skeleton data’s default skin.
    Returns a {{#crossLinkModule "sp.spine"}}sp.spine{{/crossLinkModule}}.Attachment object.

    method

    getAttachment

    Parameters

    • slotName: string
    • attachmentName: string

    Returns null | Attachment

getBlendState

getComponent

  • getComponent<T>(classConstructor: Constructor<T>): T | null
  • getComponent(className: string): Component | null
  • Returns the component of supplied type if the node has one attached, null if it doesn't.
    You can also get component in the node by passing in the name of the script.

    example
    // get custom test calss.
    var test = node.getComponent("Test");

    Type parameters

    Parameters

    • classConstructor: Constructor<T>

      The class of component to be retrieved or to be created

    Returns T | null

  • Returns the component of supplied type if the node has one attached, null if it doesn't.
    You can also get component in the node by passing in the name of the script.

    example
    // get custom test calss.
    var test = node.getComponent("Test");

    Parameters

    • className: string

      A string for the class name of the component

    Returns Component | null

getComponentInChildren

  • getComponentInChildren<T>(classConstructor: Constructor<T>): T | null
  • getComponentInChildren(className: string): Component | null

getComponents

  • getComponents<T>(classConstructor: Constructor<T>): T[]
  • getComponents(className: string): Component[]

getComponentsInChildren

  • getComponentsInChildren<T>(classConstructor: Constructor<T>): T[]
  • getComponentsInChildren(className: string): Component[]

getCurrent

  • getCurrent(trackIndex: number): null | TrackEntry
  • Returns track entry by trackIndex.
    Returns a {{#crossLinkModule "sp.spine"}}sp.spine{{/crossLinkModule}}.TrackEntry object.

    method

    getCurrent

    Parameters

    • trackIndex: number

    Returns null | TrackEntry

getMaterial

  • getMaterial(idx: number): Material | null

getMaterialForBlendAndTint

getMaterialInstance

  • getMaterialInstance(idx: number): Material | null

getRenderMaterial

  • getRenderMaterial(index: number): Material | null

getState

  • getState(): undefined | AnimationState

getTextureAtlas

  • getTextureAtlas(regionAttachment: RegionAttachment | BoundingBoxAttachment): TextureRegion
  • Return the renderer of attachment.

    method

    getTextureAtlas

    Parameters

    • regionAttachment: RegionAttachment | BoundingBoxAttachment

    Returns TextureRegion

invalidAnimationCache

  • invalidAnimationCache(): void
  • Invalidates the animation cache, which is then recomputed on each frame..

    method

    invalidAnimationCache

    Returns void

isAnimationCached

  • isAnimationCached(): boolean

Protected Optional lateUpdate

  • lateUpdate(dt: number): void
  • LateUpdate is called every frame, if the Component is enabled.
    This is a lifecycle method. It may not be implemented in the super class.
    You can only call its super class method inside it. It should not be called manually elsewhere.

    Parameters

    • dt: number

      the delta time in seconds it took to complete the last frame

    Returns void

markForUpdateRenderData

  • markForUpdateRenderData(enable?: boolean): void

onDestroy

  • onDestroy(): void

onDisable

  • onDisable(): void

onEnable

  • onEnable(): void

Optional onFocusInEditor

  • onFocusInEditor(): void

Protected Optional onLoad

  • onLoad(): void
  • When attaching to an active node or its node first activated.
    onLoad is always called before any start functions, this allows you to order initialization of scripts.
    This is a lifecycle method. It may not be implemented in the super class.
    You can only call its super class method inside it. It should not be called manually elsewhere.

    Returns void

Optional onLostFocusInEditor

  • onLostFocusInEditor(): void

onRestore

  • onRestore(): void

postUpdateAssembler

  • postUpdateAssembler(render: Batcher2D): void
  • Post render data submission procedure, it's executed after assembler updated for all children. It may assemble some extra render data to the geometry buffers, or it may only change some render states. Don't call it unless you know what you are doing.

    Parameters

    • render: Batcher2D

    Returns void

querySockets

  • querySockets(): string[]

requestMeshRenderData

requestRenderData

  • requestRenderData(): RenderData

Optional resetInEditor

  • resetInEditor(): void

schedule

  • schedule(callback: any, interval?: number, repeat?: number, delay?: number): void
  • Schedules a custom task.
    If the task is already scheduled, then the interval parameter will be updated without scheduling it again.

    example
    import { log } from 'cc';
    this.schedule((dt) => void log(`time: ${dt}`), 1);

    Parameters

    • callback: any

      The callback function of the task

    • Default value interval: number = 0

      The time interval between each invocation

    • Default value repeat: number = legacyCC.macro.REPEAT_FOREVER

      The repeat count of this task, the task will be invoked (repeat + 1) times, use macro.REPEAT_FOREVER to repeat a task forever

    • Default value delay: number = 0

      The delay time for the first invocation, Unit: s

    Returns void

scheduleOnce

  • scheduleOnce(callback: any, delay?: number): void
  • Schedules a task that runs only once, with a delay of 0 or larger.

    method

    scheduleOnce

    see

    schedule

    example
    import { log } from 'cc';
    this.scheduleOnce((dt) => void log(`time: ${dt}`), 2);

    Parameters

    • callback: any

      The callback function of the task

    • Default value delay: number = 0

      The delay time for the first invocation, Unit: s

    Returns void

setAnimation

  • setAnimation(trackIndex: number, name: string, loop: boolean): null | TrackEntry
  • Set the current animation. Any queued animations are cleared.
    Returns a {{#crossLinkModule "sp.spine"}}sp.spine{{/crossLinkModule}}.TrackEntry object.

    method

    setAnimation

    Parameters

    • trackIndex: number
    • name: string
    • loop: boolean

    Returns null | TrackEntry

setAnimationCacheMode

  • It's best to set cache mode before set property 'dragonAsset', or will waste some cpu time. If set the mode in editor, then no need to worry about order problem.

    example

    skeleton.setAnimationCacheMode(sp.Skeleton.AnimationCacheMode.SHARED_CACHE);

    Parameters

    Returns void

setAnimationStateData

  • setAnimationStateData(stateData: any): void
  • Sets animation state data.
    The parameter type is {{#crossLinkModule "sp.spine"}}sp.spine{{/crossLinkModule}}.AnimationStateData.

    Parameters

    • stateData: any

    Returns void

setAttachment

  • setAttachment(slotName: string, attachmentName: string): void
  • Sets the attachment for the slot and attachment name. The skeleton looks first in its skin, then in the skeleton data’s default skin.

    method

    setAttachment

    Parameters

    • slotName: string
    • attachmentName: string

    Returns void

setBlendHash

  • setBlendHash(): void

setBonesToSetupPose

  • setBonesToSetupPose(): void
  • Sets the bones to the setup pose, using the values from the BoneData list in the SkeletonData.

    method

    setBonesToSetupPose

    Returns void

setCompleteListener

setDisposeListener

setEndListener

setEventListener

setInterruptListener

setMaterial

  • setMaterial(material: Material | null, index: number): void

setMaterialInstance

  • setMaterialInstance(index: number, matInst: Material | null): void

setMix

  • setMix(fromAnimation: string, toAnimation: string, duration: number): void
  • Mix applies all keyframe values, interpolated for the specified time and mixed with the current values.

    method

    setMix

    Parameters

    • fromAnimation: string
    • toAnimation: string
    • duration: number

    Returns void

setSkeletonData

  • setSkeletonData(skeletonData: SkeletonData): void
  • Sets runtime skeleton data to sp.Skeleton.
    This method is different from the skeletonData property. This method is passed in the raw data provided by the Spine runtime, and the skeletonData type is the asset type provided by Creator.

    method

    setSkeletonData

    Parameters

    • skeletonData: SkeletonData

    Returns void

setSkin

  • setSkin(skinName: string): void
  • Finds a skin by name and makes it the active skin. This does a string comparison for every skin.
    Note that setting the skin does not change which attachments are visible.
    Returns a {{#crossLinkModule "sp.spine"}}sp.spine{{/crossLinkModule}}.Skin object.

    method

    setSkin

    Parameters

    • skinName: string

    Returns void

setSlotsRange

  • setSlotsRange(startSlotIndex: any, endSlotIndex: any): void

setSlotsToSetupPose

  • setSlotsToSetupPose(): void
  • Sets the slots to the setup pose, using the values from the SlotData list in the SkeletonData.

    method

    setSlotsToSetupPose

    Returns void

setStartListener

setToSetupPose

  • setToSetupPose(): void

setTrackCompleteListener

  • setTrackCompleteListener(entry: TrackEntry, listener: TrackListener2): void

setTrackDisposeListener

  • setTrackDisposeListener(entry: TrackEntry, listener: TrackListener): void

setTrackEndListener

  • setTrackEndListener(entry: TrackEntry, listener: TrackListener): void

setTrackEventListener

  • setTrackEventListener(entry: TrackEntry, listener: TrackListener): void

setTrackInterruptListener

  • setTrackInterruptListener(entry: TrackEntry, listener: TrackListener): void

setTrackStartListener

  • setTrackStartListener(entry: TrackEntry, listener: TrackListener): void

setVertexEffectDelegate

Protected Optional start

  • start(): void
  • Called before all scripts' update if the Component is enabled the first time.
    Usually used to initialize some logic which need to be called after all components' onload methods called.
    This is a lifecycle method. It may not be implemented in the super class.
    You can only call its super class method inside it. It should not be called manually elsewhere.

    Returns void

Private syncTransform

  • syncTransform(): void

unschedule

  • unschedule(callback_fn: any): void

unscheduleAllCallbacks

  • unscheduleAllCallbacks(): void

update

  • update(dt: number): void

updateAnimationCache

  • updateAnimationCache(animName: any): void
  • Updating an animation cache to calculate all frame data in the animation is a cost in performance due to calculating all data in a single frame. To update the cache, use the invalidAnimationCache method with high performance.

    method

    updateAnimationCache

    Parameters

    • animName: any

    Returns void

updateAssembler

  • updateAssembler(render: Batcher2D): void
  • Render data submission procedure, it update and assemble the render data to 2D data buffers before all children submission process. Usually called each frame when the ui flow assemble all render data to geometry buffers. Don't call it unless you know what you are doing.

    Parameters

    • render: Batcher2D

    Returns void

updateBlendHash

  • updateBlendHash(): void

Protected updateMaterial

  • updateMaterial(): void

Protected updateWorldTransform

  • updateWorldTransform(): void
  • Computes the world SRT from the local SRT for each bone.

    method

    updateWorldTransform

    example

    var bone = spine.findBone('head'); cc.log(bone.worldX); // return 0; spine.updateWorldTransform(); bone = spine.findBone('head'); cc.log(bone.worldX); // return -23.12;

    Returns void

Static deferredDestroy

  • _deferredDestroy(): void

Generated using TypeDoc