Game Development Community

New onAnimationEnd problem ?

by Matthew Langley · in Torque Game Builder · 04/21/2005 (9:49 am) · 14 replies

Not sure if this is a bug yet, so posting it here

before the recent release the onAnimationEnd callback got called continuosly after it ended... now it doesn't do that anymore; however, in creating an animation queueing system it doesn't seem to do chain callbacks... it will only call the callback once, even if in the callback you have it play another animation, the callback wont get called then

heres what I tested it with (the same example I have in the Unofficial F.A.Q.)... I dumbed it down to a simple example (vs the queueing system)

$circleGuy = new fxAnimatedSprite2D() { scenegraph = t2dSceneGraph; };
        
        $circleGuy.setPosition("-35 0");
        $circleGuy.setSize( "10 7" );
        $circleGuy.playAnimation(circleGuyStandLeft);
	
$circleGuy.direc = "left";

function fxAnimatedSprite2D::onAnimationEnd(%this)
{
	echo("---onAnimationEnd---");
	if(%this.direc $= "right")
	{	
		$circleGuy.playAnimation(CircleGuyStandLeft);
		%this.direc = "left";
	} else
	{
		$circleGuy.playAnimation(CircleGuyStandRight);
		%this.direc = "right";
	}
}

maybe someone else can test this with their own example to see if its just me :)

About the author

Was a GG Associate and then joined GG in 2005. Lead tool dev for T2D and T3D. In 2011 joined mobile company ngmoco/DeNA and spent about 4 years working game and server tech. 2014 joined startup Merigo Games developing server technology.


#1
04/21/2005 (9:50 am)
In my console I only get one

---onAnimationEnd---

and it switches once

though even if the switching weren't working it should trigger the callback still
#2
04/21/2005 (11:03 am)
Same thing happens to me (using 1_0_2). I made the animationCycle true, thinking that might have an effect, but then it never gets to onAnimationEnd more than once.
#3
04/21/2005 (11:05 am)
Yeah, even on animationCycle False...then loading a whole other animation it still triggers only once...

was glimpsing at the source code and notice Melv added a bool to trigger when the animation callback happens so it doesn't happen more than once, seems it just needs reset in a different or another spot... (I may be completely incorrect in my assumptions too lol)... but then again thats what we the EAers are here for :)
#4
04/21/2005 (11:24 am)
Based on what you said about the source, I solved your problem, King Tut!

Schedule this function from within onAnimationEnd, and you're in bidness:

function MakeNewCircleGuy()
{
        if (IsObject($circleGuy)) $circleGuy.safeDelete();
        $circleGuy = new fxAnimatedSprite2D() { scenegraph = t2dSceneGraph; };
        
        $circleGuy.setPosition("-35 0");
        $circleGuy.setSize( "10 7" );
        $circleGuy.playAnimation(circleGuyStandLeft);
}

I know, I know you are eternally grateful
#5
04/21/2005 (12:45 pm)
I was just going to post about this problem myself. I was trying to work out a more useable animation system and could not for the love of all that is good get onAnimationEnd to trigger beyond the first time for a given fxAnimatedSprite2D.

Kevin: Unless I am totally misunderstanding how T2D is supposed to work, I can at least say from my years of programming experience that deleting and creating a new object to get around a problem like this is absolutely not a good way to do it.
#6
04/21/2005 (12:46 pm)
King: Funny how your example and problem is exactly like the one I was going to post on here :)

I guess someone should put up a bug report for this. And more importantly, I hope someone can make a fix because I can do absolutely nothing while this bug is in effect.
#7
04/21/2005 (3:28 pm)
Yeah, Tomas, I was kidding.
#8
04/21/2005 (5:49 pm)
Just to note, this didn't happen w/ 1.0.0, right?

We'll check it out, thanks guys. :)
#9
04/21/2005 (5:55 pm)
With 1.0.0 onAnimationEnd() kicked into an infinite loop when called, the new bool value Melv added was to fix that
#10
04/22/2005 (2:30 am)
Oh yeah, durr. :) Well, we'll have to look at this a bit more carefully. Thanks Matt.
#11
04/22/2005 (6:12 am)
I think is my bad, sorry everyone. :(

The flag as discussed here was being reset after the callback rather than before it so restarting the animation in the callback was being suppressed upon its return. I've posted a minor fix here but please be aware that I'm currently at work and have not tested this.

- Melv.
#12
04/23/2005 (4:23 pm)
Well you fixed the previous bug, that is an amazingly easy thing to not notice, lol you just have your team of EAers here to drill in and find anything like this for you :)
#13
04/24/2005 (2:06 am)
Thanks everyone. :)

It's always the little things that get you.

*Makes mental note - adjust state before any script-callbacks 'cause you never know what's going to happen in them* :)

- Melv.
#14
04/24/2005 (2:15 am)
Don't feel bad Melv... there are other sections of the TGE code that have simliar behaviour.... it's the nature of the single thread Torque runs with. Usually doing an immediate (or semi-immediate) schedule will sidestep the issue.