spine
spine copied to clipboard
How to reset the animation to first frame?
I've tryed "skeleton.setToSetupPose();" and similar but nothing works Resetting an animation is very important, why there's no method to do it? Besides that I think there should be a method to set the animation at desired frame, based on zero to one interpolation (ex. if I want to set the animation in the middle I just write animation.update(.5)) For now update method is very confusing.
This worked for me: // skeleton animation.skeleton.setToSetupPose(); animation.state.tracks = [];
so, that clears all animations?
Yes all the animations are cleared and you have to add them again. Here is some of my code below to illustrate (I made a SpineSprite class)
I have start, stop, and rewind methods.
In the start method I initialize the animation again. I remove the onCompleteListener after a rewind - since it otherwise keeps on playing, when I play an empty animation - to simulate that it has stopped
SpineSprite.prototype.rewind = function() {
if (this.onCompleteStateAdded) {
this.onCompleteStateAdded = false;
//console.log(this.sprite.state);
this.sprite.state.listeners = [];
}
this.sprite.skeleton.setToSetupPose();
this.sprite.state.tracks = [];
}
SpineSprite.prototype.start = function(keepRepeating, onCompleteCallback) {
this.sprite.state.setAnimation(0, this.animation, keepRepeating);
if (onCompleteCallback) {
var self = this;
this.sprite.state.addListener({
complete: function(entry) {
onCompleteCallback(entry);
if (!keepRepeating) {
self.stop();
}
}
});
this.onCompleteStateAdded = true;
}
}
SpineSprite.prototype.stop = function() {
this.rewind();
this.sprite.state.setEmptyAnimation(0);
}
state.clearTrack(trackIndex);
skeleton.setToSetupPose()
worked for me
Nice, that'll go into readme
@simzard thank a lot , this avoid me to use state.clearTrack(1); state.addAnimation(1, 'wink1', false, ranWait);
this work good for me
state.data.defaultMix = 1;
state.setEmptyAnimation(0,1);
state.setAnimation(0,'idle4',true),
I dont know how to reset the animation to first frame,But i know how to reset the animation to last frame.I hope it will help you. Spine.TrackEntry trackEntry = mSkeletonGraphic.AnimationState.Tracks.Items[index]; trackEntry.Loop = false; trackEntry.TrackTime = trackEntry.TrackEnd;
According to the Spine API that is nearly impossible to find, http://esotericsoftware.com/spine-applying-animations/
The "right" way to do it is to use addEmptyAnimation
or setEmptyAnimation
, with a crossfade number, to not have instantaneous transitions.
state.setAnimation(track, "run", true, 0);
state.addEmptyAnimation(track, 1.5, 0);
The problem is later, if I try to restart for example the run
animation on the same track #, it simply won't start. No idea how to fix that.
This solved my problem:
//@ts-ignore
this.spine.lastTime = null; // reset timer (private field of spine)
this.spine.state.setAnimation(0, animName, loop);
how to reset the animation to first frame
obj.state.tracks[0].trackTime = 0; obj.update(0);
but then it just keeps playing so you have to clear the track or something
Thanks guys, this one works like a charm for me
public clearState() {
this.state.clearTracks();
this.skeleton.setToSetupPose();
this.lastTime = null;
}
helped me temporarily
this.state.setAnimation(0, 'animation', false);
this.state.update(1);
this.state.timeScale = 1;
or
this.state.setAnimation(0, 'animation', false);
this.state.update(0);
this.state.timeScale = 0;