Hello 🙂
Here is the function that is invoked by the ticker attached to the Spine object.
As you can see, it performs the following operations:
...
this.state.update(time);
this.skeleton.update(time);
const { skeleton } = this;
this.state.apply(skeleton);
this.beforeUpdateWorldTransforms(this);
skeleton.updateWorldTransform(Physics.update);
this.afterUpdateWorldTransforms(this);
...
The skeleton.updateWorldTransform
is always updated with Physics.update
.
You can approach this in two ways:
- Manually write your own update logic.
- Use the
afterUpdateWorldTransforms
hook to invoke updateWorldTransform
with Physics.reset
.
The second approach is more straightforward, though slightly tricky. You need to set Physics.reset
for a single frame and then revert it; otherwise, the physics system will stop working. Here's an example of how you could implement this:
spineObject.state.setAnimation(0, "eyeblink", true); // Set a new animation
const prevAfterUWT = spineObject.afterUpdateWorldTransforms; // Store the current version of afterUpdateWorldTransforms
// Set a custom afterUpdateWorldTransforms hook to be invoked just once
spineObject.afterUpdateWorldTransforms = () => {
// Invoke updateWorldTransform with Physics.reset
spineObject.skeleton.updateWorldTransform(spine.Physics.reset);
// Restore the previous afterUpdateWorldTransforms hook
spineObject.afterUpdateWorldTransforms = prevAfterUWT;
};