How can I play an animation once?
The code I have works with a looping animation, but not when I do not want it to loop. The animation simply doesn’t play.
AnimateCommand.attributes.add('object', {type: 'entity'});
AnimateCommand.attributes.add('animation', {
type: 'json',
title: 'Animation Asset',
schema: [{
name: 'stateName',
title: 'State Name',
type: 'string',
}, {
name: 'asset',
title: 'Asset',
type: 'asset',
assetType: 'animation'
}]
});
AnimateCommand.attributes.add('delay', {type: 'number', title: 'Delay in seconds'});
AnimateCommand.prototype.initialize = function() {
//works when last parameter is 'true'
this.object.anim.assignAnimation(this.animation.stateName, this.animation.asset.resource, 1, false);
this.object.anim.speed = 0;
};
AnimateCommand.prototype.execute = function() {
setTimeout(() => {
this.object.anim.baseLayer.play(this.animation.stateName);
this.object.anim.speed = 1;
}, this.delay * 1000);
};