<spine-skeleton> tag allows you to embed your Spine animations into a web page as a web component.
fit attribute.
fit="fill". The default fit value is fit="contain".
fit="none".
In combination with that, you can use the scale attribute to set your desired scale.
width, height, cover, and scaleDown.
width and height attributes in pixels (without the "px" unit).
style attribute, which provides more styling options.
origin mode centers the animation's world origin with the center of the HTML element.
x-axis and y-axis attributes, respectively.
offset-x and offset-y to move your skeleton left or right by the specified number of pixels.
pad-left, pad-right, pad-top, and pad-bottom.
bounds-x, bounds-y, bounds-width, and bounds-height attributes allow you to define custom bounds.
clip in this case to prevent the skeleton from overflowing.
identifier to your widget to retrieve it using the spine.getSpineWidget function.
You can easily access the Skeleton and AnimationState of your character, and use them as if you were working with spine-webgl.
To change the animation, you can simply modify the animation attribute. The widget will reinitialize itself and switch to the new animation.
In this case, you should use auto-calculate-bounds to have the widget always recalculate the bounds, as shown in the top example.
If you want to keep the scale consistent while fitting multiple animations in the container, you can use the animation-bounds attribute to define bounds that include a list of animations, as shown in the bottom example.
If you want to display a sequence of animations without using JavaScript, you can use the animations attribute.
It accepts a string composed of groups enclosed in square brackets, like this: [...][...][...]
Each group represents an animation to play, with parameters in a comma-separated list:
track: the track number to play the animation onanimation name: the name of the animationloop: true to loop the animation, false otherwisedelay: the number of seconds to wait after the previous animation starts (not used for the first animation on a track)mixDuration: the mix duration between this animation and the previous one (not used for the first animation on a track)To loop a track once it reaches the end, add the special group [loop, trackNumber], where:
loop: identifies this as a loop instructiontrackNumber: the number of the track to loopThe parameters of the first group on each track are passed to the setAnimation method, while the remaining groups use addAnimation.
To use setEmptyAnimation or addEmptyAnimation, use #EMPTY# as the animation name. In this case, the loop parameter is ignored.
The default-mix attribute allows you to set the default mix duration for the AnimationState.
See the two examples below.
Spineboy uses the following value for the animations attribute:
We use a single track for this animation. Let's break it down:
[loop, 0]: when track 0 reaches the end, it loops back to the beginning[0, idle, true]: sets the idle animation to loop[0, run, false, 2, 0.25]: queues the run animation, starts it after 2 seconds with a 0.25-second mix[0, run, false]: queues another run animation[0, run, false]: queues another run animation[0, run-to-idle, false, 0, 0.15]: queues run-to-idle with no delay and a 0.15-second mix[0, idle, true]: queues the idle animation to loop[0, jump, false, 0, 0.15]: queues jump with no delay and a 0.15-second mix[0, walk, false, 0, 0.05]: queues walk with no delay and a 0.05-second mix[0, death, false, 0, 0.05]: queues death with no delay and a 0.05-second mixCeleste uses the following value for the animations attribute:
This example uses two tracks. Track 0 plays the wings-and-feet animation.
Track 1 loops, playing an empty animation followed by an eyeblink animation with a 2-second delay.
You can modify the textarea above and experiment. For example, change the delay from 2 to 0.5, or add the swing animation to track 0 like this: [0, swing, true, 5, 0.5] to start it after 5 seconds with a 0.5-second mix. Click the button below and Celeste will start blinking more frequently.
inside mode, but not when in origin mode.
debug to true.
dispose() on it.
dispose() is safe and won't release resources if they're still used by other widgets.
dispose() on the overlay.
The following example allows you to create and dispose of widgets using the same assets. Below, you can see the number of references to each asset. A red message will appear when an asset is actually disposed. If the number of skeleton references is higher than expected, it's because other widgets on the page are still using it.
Widgets: ?
no-spinner.
skin and animation attributes.
pages attribute as a comma-separated list of indices.
spine.createSpineWidget allows you to create a Spine widget.
manual-start="false".
Then, add the widget to the DOM using the asynchronous method appendTo. It is your responsibility to call start() on the widget.
As usual, just wait for the whenReady to interact with the skeleton or the state.
onScreenFunction is invoked.
onScreenAtLeastOnce to true when the widget enters the viewport for the first timestart-when-visible is set, the widget's start method is invoked the first time the widget enters the viewport, and the assets are loaded at that moment.onScreenFunction behavior. For example, the raptor below changes its animation every time the widget enters the viewport.
pages="".
update, and the skeleton apply and the skeleton updateWorldTransform functions are not invoked when the widget is off-screen.
offscreen=update.
offscreen=pose.
update property of the widget.
In that case, it's your responsibility to skip the update/apply. You can use the onScreen property for convenience.
clip property to clip everything that is outside the HTML container.
clip attribute.
spine-overlay web component as a direct child of the container.
Moreover, it is necessary to perform the following actions: transform CSS attribute. If it doesn't have this attribute, the spine-overlay will add it for you.
If you don't want this attribute to be added, set the no-auto-parent-transform on the spine-overlay. But watch out, the widget might not work as intended.
spine-overlay must have an overlay-id attribute. Choose the value you prefer.
spine-skeleton must have an overlay-id attribute. The same as the hosting spine-overlay.
overflow-top, overflow-bottom, overflow-left, overflow-right attributes to the spine-overlay in order to make the canvas bigger and prevent scrolling artifacts.
isdraggable property to true.
spine-skeleton:
cursorWorldX and cursorWorldY are the x and y of the cursor relative to the skeleton root (spine world).worldX and worldY are the x and y of the root relative to the canvas/webgl context origin (spine world).spine-overlay:
cursorCanvasX and cursorCanvasY are the x and y of the cursor relative to the canvas top-left corner (screen world).cursorWorldX and cursorWorldY are the x and y of the cursor relative to the canvas/webgl context origin (spine world).
isinteractive.
bounds or with slots.
The available events are down, up, enter, leave, move, and drag.
head-base slot (the face), you can change the normal and dark tint with the colors selected in the two following selectors.
Tint normal:
Tint black:
HTMLElements follow slots. This feature is convenient when you need to generate dynamic text or content that integrates with your animation.
Invoke the `followSlot` function that takes as input:
Slot or the slot name to followHTMLElement that follows the slotfollowOpacity: the element opacity is connected to the slot alphafollowScale: the element scale is connected to the slot scalefollowRotation: the element rotation is connected to the slot rotationfollowAttachmentAttach: the element is shown/hidden depending if the slot contains an attachment or nothideAttachment: the slot attachment is hidden as if the element replaced the attachment