Monday, 19 August 2013

KineticJS afterFrame doesn't run on loop

KineticJS afterFrame doesn't run on loop

I tried to have a reloading animation change values for my character. I
want player.shots to go up by 1 every time the animation loops. However,
it runs once and the animation continues Here is the code I have.
gun.setAnimation('reload');
gun.afterFrame(6,function(){
console.log('reload');
player.shots++;
if(player.shots > 5){
gun.setAnimation('idle');
}
}
Interestingly, if an error occurs in the function it works like expected.
gun.setAnimation('reload');
gun.afterFrame(6,function(){
console.log('reload');
player.shots++;
if(player.shots > 5){
gun.setAnimation('idle');
}
console(y) //this is an intentional error
}
This leads me to believe that afterFrame determines if it should run on
the next iteration or not based on a return value.
Is there any nice workaround or parameter I need to add, or should I just
keep intentionally causing an error to get the desired behavior?

No comments:

Post a Comment