Hi All,
My students want to have ONE sprite, with multiple animations - and then have the program “check” which animation is showing, and then if a certain animation is showing, then something will happen.
I can’t really give an example because I can’t figure out what to do…
but it’d be something like
IF a sprite’s animation == something, then -whatever- will happen.
Hopefully this makes sense to someone, sorry if it’s unclear. I’ve wondered this for years.
greetings @emily.kosmack,
i believe i know what your asking for would something like this do?
var spr = createSprite(200,200);
spr.setAnimation("animation")
console.log(spr.getAnimationLabel());
the .getAnimationLabel()
is a custom property of the sprite which will give the current animation name of the sprite being used at the given moment of which you will be able to write a comparable if statement
Varrience
Hi @varrience, I so appreciate your response!
I’m just not sure what to write in the if statement. This is what I’m working with.
hello again @emily.kosmack,
the demo code i showed was mainly for you to tinker and figure out how it works, since your struggling i’ll clarify your solution, when checking for .getAnimationLabel()
on a sprite it returns a string
which you can then use on the comparison line 7 within your program here is how that line would look
if (animal.getAnimationLabel() == "animalhead_elephant_2_1") {
by using the function call in the comparison statement we convert the animal’s animation name into a boolean string comparison expression
hope this clarifies it
Varrience
1 Like
Thank you so much for all the help. I would have not figured this out on my own - I’m just a middle school teacher, not a programmer 
Your explanation makes sense and now I can use this new knowledge in other ways. Thank you!!!
1 Like