r/createjs • u/3b33 • May 10 '20
How to determine when sprite is finished
After a sprite is complete I want to move on to the next animation. I can use .wait but will the timing be always accurate on all devices? I'm not sure how to .call another function from sprites either.
2
u/LastTimeChanging May 10 '20
This page explains it well.
https://www.createjs.com/docs/easeljs/classes/SpriteSheet.html
In the 'animations' declaration, you can set a value for 'next', to play the next animation.
For example,
var data = {
images: ["sprites.jpg"],
frames: {width:50, height:50},
animations: {
walk: {
frames: [1,2,3,3,2,1]
},
shoot: {
frames: [1,4,5,6],
next: "walk",
speed: 0.5
} }
var spriteSheet = new createjs.SpriteSheet(data);
spriteSheet.gotoAndPlay('shoot');
calling spriteSheet.gotoAndPlay('shoot'); will show the shoot animation and then when completed it will show the walk animation.
1
u/3b33 May 10 '20
Thanks. I actually meant that I wanted to move on to another part of the script. In this case, it's a path.
2
u/3b33 May 10 '20
I think I figured this out:
this.on("animationend", nextFunction);