defold/extension-spine/spine
Functions and constants for interacting with Spine models
- GitHub: defold/extension-spine — pinned to
4.8.0(released while Defold 1.13.1 was current)- Pick a release from defold/extension-spine releases and add its Source code (zip) URL (or a packaged
.zipasset, if the library ships one) togame.projectunder[project]dependencies, then Fetch Libraries in the Defold editor. - Run
bunx @defold-typescript/cli resolveto materialize its types. - Import it under a namespace alias of your choice:
import * as spine from "spine"
- Pick a release from defold/extension-spine releases and add its Source code (zip) URL (or a packaged
Functions
spine.play_anim(url: string | hash | url, anim_id: string | hash, playback: number, options: table | nil, callback_function: function)spine.cancel(url: string | hash | url, options: table)spine.get_go(url: string | hash | url, bone_id: hash): hashspine.set_skin(url: string | hash | url, skin: string | hash)spine.add_skin(url: string | hash | url, skin_a: string | hash, skin_b: string | hash)spine.copy_skin(url: string | hash | url, skin_a: string | hash, skin_b: string | hash)spine.clear_skin(url: string | hash | url, skin: string | hash)spine.set_attachment(url: string | hash | url, slot: string | hash, attachment: string | hash | nil)spine.set_slot_color(url: string | hash | url, slot: string | hash, color: vector4)spine.reset_constant(url: string | hash | url, constant: string | hash)spine.reset_ik_target(url: string | hash | url, ik_constraint_id: string | hash)spine.set_ik_target_position(url: string | hash | url, ik_constraint_id: string | hash, position: vector3)spine.set_ik_target(url: string | hash | url, ik_constraint_id: string | hash, target_url: string | hash | url)spine.physics_translate(url: string | hash | url, translation: vector3)spine.physics_rotate(url: string | hash | url, center: vector3, degrees: number)
spine.play_anim(url: string | hash | url, anim_id: string | hash, playback: number, options: table | nil, callback_function: function)
Plays the specified animation on a Spine model. A [ref:spine_animation_done] message is sent to the callback (or message handler). Any spine events will also be handled in the same way. The callback is not called (or message sent) if the animation is cancelled with [ref:spine.cancel]. The callback is called (or message sent) only for animations that play with the following playback modes * go.PLAYBACK_ONCE_FORWARD * go.PLAYBACK_ONCE_BACKWARD * go.PLAYBACK_ONCE_PINGPONG
Parameters
url:string | hash | url— The Spine model for which to play an animationanim_id:string | hash— Id of the animation to playplayback:number— Playback mode of the animation (from go.PLAYBACK_*)options:table | nil— Playback options. ⚠️trackis 1-based; passed tospineunchanged.blend_duration:number— Duration of a linear blend between the current and new animation.offset:number— The normalized initial value of the animation cursor when the animation starts playing.playback_rate:constant— The rate with which the animation will be played. Must be positive.track:number— The track index of the animation. Defaults to 1. Animations on different tracks play in parallel.mix_blend:constant— The mix blend mode for the animation (from spine.MIX_BLEND_*). Defaults tospine.MIX_BLEND_REPLACE. Ignored for animations on the first track.alpha:number— 0 applies the current or setup value (depending on mix_blend). 1 applies the timeline value. Between 0 and 1 applies a value between the current or setup value and the timeline value. Defaults to 1.
callback_function:function— function to call when the animation has completed or a Spine event occurred. ⚠️trackis 1-based; passed tospineunchanged.self:object— The context of the calling scriptmessage_id:hash— The name of the message ("spine_animation_done" or "spine_event")message:table— A table that contains the responseanimation_id:hash— The animation that was completedtrack:number— The track index of the animationplayback:constant— (spine_animation_done only!) The playback mode for the animationevent_id:hash— (spine_event only!) the event that was triggered.blend_weight:float— (spine_event only!) Deprecated. Always 0.t:float— (spine_event only!) the time at which the event occurred (seconds)integer:int— (spine_event only!) a custom integer associated with the event (0 by default).float:float— (spine_event only!) a custom float associated with the event (0 by default)string:hash— (spine_event only!) a custom string associated with the event (hash("") by default)
sender:url— The invoker of the callback - the Spine model component
spine.cancel(url: string | hash | url, options: table)
Cancels all running animations on a specified spine model component
Parameters
url:string | hash | url— The Spine model for which to cancel the animationoptions:table— Cancel options. ⚠️trackis 1-based; passed tospineunchanged.track:number— The index of the track which to cancel the animation on. Defaults to all animations on all tracks.
spine.get_go(url: string | hash | url, bone_id: hash): hash
Returns the id of the game object that corresponds to a specified skeleton bone. Before using this function, make sure the "Create Go Bones" option is enabled in your Spine model.
Parameters
url:string | hash | url— The Spine model to querybone_id:hash— Id of the corresponding bone
Returns
id:hash— Id of the game object
spine.set_skin(url: string | hash | url, skin: string | hash)
Sets the spine skin on a spine model.
Parameters
url:string | hash | url— The Spine model to queryskin:string | hash— Id of the corresponding skin
spine.add_skin(url: string | hash | url, skin_a: string | hash, skin_b: string | hash)
Adds one spine skin on a spine model to another on the same model.
Parameters
url:string | hash | url— The Spine model to queryskin_a:string | hash— Id of the corresponding skin that will recieve the added skinskin_b:string | hash— Id of the corresponding skin to add
spine.copy_skin(url: string | hash | url, skin_a: string | hash, skin_b: string | hash)
Copies one spine skin on a spine model to another on the same model.
Parameters
url:string | hash | url— The Spine model to queryskin_a:string | hash— Id of the corresponding skin that will recieve the copied skinskin_b:string | hash— Id of the corresponding skin to copy.
spine.clear_skin(url: string | hash | url, skin: string | hash)
Clear all attachments and constraints from a skin on a spine model
Parameters
url:string | hash | url— The Spine model to queryskin:string | hash— Id of the corresponding skin
spine.set_attachment(url: string | hash | url, slot: string | hash, attachment: string | hash | nil)
Set the attachment of a slot on a spine model.
Parameters
url:string | hash | url— The Spine model to queryslot:string | hash— Id of the slotattachment:string | hash | nil— Id of the attachment. May be nil to reset to default attachment.
spine.set_slot_color(url: string | hash | url, slot: string | hash, color: vector4)
Set the color a slot will tint its attachments on a spine model.
Parameters
url:string | hash | url— The Spine model to queryslot:string | hash— Id of the slotcolor:vector4— Tint applied to attachments in a slot
spine.reset_constant(url: string | hash | url, constant: string | hash)
Resets a shader constant for a spine model component. (Previously set with go.set())
Parameters
url:string | hash | url— The Spine model to queryconstant:string | hash— name of the constant
spine.reset_ik_target(url: string | hash | url, ik_constraint_id: string | hash)
reset the IK constraint target position to default of a spinemodel.
Parameters
url:string | hash | url— The Spine modelik_constraint_id:string | hash— id of the corresponding IK constraint
spine.set_ik_target_position(url: string | hash | url, ik_constraint_id: string | hash, position: vector3)
set the target position of an IK constraint object.
Parameters
url:string | hash | url— The Spine modelik_constraint_id:string | hash— id of the corresponding IK constraintposition:vector3— target position
spine.set_ik_target(url: string | hash | url, ik_constraint_id: string | hash, target_url: string | hash | url)
set the IK constraint object target position to follow position.
Parameters
url:string | hash | url— The Spine model to queryik_constraint_id:string | hash— id of the corresponding IK constrainttarget_url:string | hash | url— target game object
spine.physics_translate(url: string | hash | url, translation: vector3)
Apply a physics-based translation to the Spine model.
Parameters
url:string | hash | url— The Spine model component to translate.translation:vector3— The translation vector to apply to the Spine model.
spine.physics_rotate(url: string | hash | url, center: vector3, degrees: number)
Apply a physics-based rotation to the Spine model.
Parameters
url:string | hash | url— The Spine model component to rotate.center:vector3— The center point around which to rotate.degrees:number— The rotation angle in degrees.