I’ve been having issues with getting animations to start and stop based on condition (i.e. true or false). I posted an example PG yesterday, and @sebavan solved the issue. However, I realized that yesterday’s example didn’t really replicate the issue I’m having in my project closely enough.
So…
Here’s a new PG, and a new problem to solve:
If the rabbit hasEnergy = true, then the jumping animation should start.
When it runs out of energy and hasEnergy = false, the falling animation should start.
I spent an entire day trying every combination of code I could think of to get this working . Being new to programming, I’m sure there is something simple I’m overlooking…
Afraid i don’t have time to make an example,
But look into get / set functions
I’m sure this will solve your problem.
On set function,
if boolean is true, start animation
If false, stop animation
Would using get / set functions be different from what I have in the PG?
if (rabbitClone.metadata.hasEnergy == true){
scene.beginAnimation(rabbitClone.skeleton, 0, 72, true, 1);
};
In my project, this approach works for everything except for starting and stopping animations.
For instance, in the PG below, the rabbits spins when the boolean is true, then falls when it switches to false.
then you can calculate and add exactly how much it should spin/rotate and how long time it should take to spin/rotate that predefined amount, giving you a lot more consistency
Thanks for taking the time to make an example PG, and for the detailed explanations, I really appreciate it! I haven’t worked with classes and get / set functions yet, so this will be a good way for me to learn these elements of JavaScript.