<spine-widget>
tag allows you to place your Spine animations into a web page.
fit
attribute.
fit="fill"
. Default fit value is fit="contain"
.
fit="none"
.
In combination with that, you can use the scale
attribute to choose you desired scale.
width
, width
, height
, cover
,and scaleDown
.
width
and height
in pixels (without the px unit).
style
attribute. There you have more styling options.
origin
center the animation world origin with the center of the HTML element.
x-axis
and y-axis
respectively.
offset-x
and offset-y
to move you skeleton left or right by the pixel amount you specify.
pad-left
, pad-right
, pad-top
, pad-bottom
.
bounds-x
, bounds-y
, bounds-width
and bounds-height
allows to define custom bounds.
clip
in this case to avoid the skeleton overflow.
identifier
to your widget to get it by using the spine.getSpineWidget
function.
You can easily access the Skeleton
and the AnimationState
of your character, and use them as if you were using spine-webgl
.
To change animation, we could also just change the animation attribute. The widget will reinitiate itself and change animation.
In this case you would use auto-recalculate-bounds
to ask the widget to always recalculate the bounds, as in the top example.
If want to keep the scale consistent, but fit multiple animations in the container, you can use the animation-bounds
attribute to define a bounds containing a list of animations, as in the bottom example.
If you want to display a sequence of animations without using js or on multiple tracks, you can use the animations
attribute.
It accepts a string composed of groups surrounded by square brackets, like this: [...][...][...]
Each square bracket represents an animation to play, with some parameters. It contains a comma separated list with the following:
track
: the number of the track on which to play the animationanimation name
: the name of the animation to playloop
: true, if this animation has to loop. False, otherwisedelay
: the seconds to wait after the start of the previous animation, to play the animatino of this group (not available for the first animation on this track)mixDuration
: the mix duration between this animation and the previous (not available for the first animation on this track)Once you composed your animation, if you that is loops once it reaches the end, you can add the special group [loop, trackNumber]
, where:
loop
: is the "loop" string to identify this special grouptrackNumber
: is the number of the track you want to be loopedThe parameters of the first group of each track are passed to the `setAnimation` method, while the remaining groups on the track use `addAnimation`.
You can use respectively use `setEmptyAnimation` or `addEmptyAnimation`, by using the string #EMPTY#
as animation name. In this case the loop
parameter is ignored.
The default-mix
attribute allow to the the default mix of the AnimationState
.
Have a look at the two examples below.
Spineboy here uses the following value for animations
attribute.
We use a single track for this animation. Let's analyze it:
[loop, 0]
: when the track 0 reaches the end, start from the beginning[0, idle, true]
: set the idle animation in loop[0, run, true, 2, 0.25]
: queue a cycle of the run animation, start it after 2 seconds from the beginning of the previous one, set a mix of 0.25 seconds from the previous one.[0, run, false]
: queue a cycle of run animation[0, run, false]
: queue a cycle of run animation[0, run-to-idle, false, 0, 0.15]
: queue a cycle of run-to-idle animation, with no delay, and a mix of 0.15 seconds[0, idle, true]
: queue the idle animation in loop[0, jump, false, 0, 0.15]
: queue a cycle of jump animation in loop, with no delay, and a mix of 0.15 seconds[0, walk, false, 0, 0.05]
: queue a cycle of walk animation in loop, with no delay, and a mix of 0.05 seconds[0, death, false, 0, 0.05]
: queue a cycle of death animation in loop, with no delay, and a mix of 0.05 secondsCeleste here uses the following value for animations
attribute.
It uses two tracks. In track 0 we simply set the wings-and-feet animation.
In track 1 we loop over the entire animation, set an empty animation and queue an eyeblink animation with a 2 seconds delay.
You can modify the textarea above and experiment with the values. For example, change the delay from 2 to 0.5, or add the swing animation to track 0 like this [0, swing, true, 5, .5]
with a delay of 5 seconds and a mix of 0.5 seconds. Click the button below and Celeste will start to blink the eyes more frequently.
inside
mode, but not in origin
mode.
debug
to true
.
spinner="false"
.
skin
and animation
attributes.
pages
the atlas pages you want to load as a comma concatenated 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's your responsibility to call start()
on the widget.
As usual, just wait on the loadingPromise
to act on the skeleton
or the state
.
onScreenFunction
is invoked.
onScreenAtLeastOnce
to true
when the widget enters the viewport the first timemanual-start
and on-screen-manual-start
are set the widget start
is invoked
the first time the widget enters the viewport and the assets are loaded only in that moment.onScreenFunction
behaviour. For example, the raptor below changes animation everytime 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 it's your responsibility to skip the update/apply. You can use the onScreen
property for convinience.
clip
property to clip everything is outside the html container.
clip
attribute.
spine-overlay
webcomponent as a direct child of the container.
Moreover, it is necessary to perform the following actions: transform
css attribute. If it hasn't this attribute the spine-overlay
will add it for you.
If your scrollable container has already this css attribute, or if you prefer to add it by yourself (example: transform: translateZ(0);
), set the scrollable-tweak-off
to the spine-overlay
.
spine-overlay
must have the scrollable
attribute
spine-overlay
must have an overlay-id
attribute. Choose the value you prefer.
spine-widget
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-widget
:
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:
HTMLElement
s 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 slots contains an attachment or nothideAttachment
: the slot attachment is hidden as if the element replaced the attachment
The chibi sticker does the following:
The button does the following:
LOGIN
text to a slot