Spine Model

The SpineModel component is used to bring Spine skeletal animations to life in Defold.

Creating SpineModel components

Select a game object to hold the new component:

Either create the component in-place (right click the game object and select Add Component ▸ Spine Model)

Or create it on file first (right click a location in the Assets browser, then select New... ▸ Spine Model from the context menu), then add the file to the game object by right clicking the game object and selecting Add Component File).

Spine model properties

Apart from the properties Id, Position and Rotation the following component specific properties exist:

Spine scene
Set this to the Spine scene file you created earlier.
Blend Mode
If you want a blend mode other than the default Alpha, change this property.
Material
If you need to render the model with a custom material, change this property.
Default animation
Set this to the animation you want the model to start with.
Skin
If your model has skins, select the one you want it to start with.

You should now be able to view your Spine model in the editor:

Spine model in editor

Blend modes

The Blend Mode property defines how the component graphics should be blended with the graphics behind it. These are the available blend modes and how they are calculated:

Alpha
Normal blending: a~0~ * rgb~0~ + (1 - a~0~) * rgb~1~
Add
Brighten the background with the color values of the corresponding pixels of the component: rgb~0~ + rgb~1~
Multiply
Darken the background with values of the the corresponding pixels of the component: rgb~0~ * rgb~1~

Runtime manipulation

You can manipulate spine models in runtime through a number of different functions and properties (refer to the API docs for usage).

Runtime animation

Defold provides powerful support for controlling animation in runtime:

local play_properties = { blend_duration = 0.1 }
spine.play_anim("#spinemodel", "jump", go.PLAYBACK_ONCE_FORWARD, play_properties)

The animation playback cursor can be animated either by hand or through the property animation system:

-- set the run animation
spine.play_anim("#spinemodel", "run", go.PLAYBACK_NONE)
-- animate the cursor
go.animate("#spinemodel", "cursor", go.PLAYBACK_LOOP_PINGPONG, 1, go.EASING_LINEAR, 10)

Changing properties

A spine model also has a number of different properties that can be manipulated using go.get() and go.set():

animation
The current model animation (hash) (READ ONLY). You change animation using spine.play_anim() (see above).
cursor
The normalized animation cursor (number).
material
The spine model material (hash). You can change this using a material resource property and go.set(). Refer to the API reference for an example.
playback_rate
The animation playback rate (number).
skin
The current skin on the component (hash).

Material constants

The default spine material has the following constants that can be changed using spine.set_constant() and reset using spine.reset_constant() (refer to the Material manual for more details):

tint
The color tint of the spine model (vector4). The vector4 is used to represent the tint with x, y, z, and w corresponding to the red, green, blue and alpha tint. Refer to the API reference for an example.

Project configuration

The game.project file has a few project settings related to spine models.


Did you spot an error or do you have a suggestion? Please let us know on GitHub!

GITHUB