Game Development Community

OnAnimationEndDelegate

by Amit Mathew · in Torque X 2D · 04/28/2007 (1:55 pm) · 3 replies

I'm trying to perform some action when a given animation ends, but so far I've had no luck getting the onAnimationEndDelegate to fire. I've tried setting the OnAnimationEnd member and using ProcessList.AddAnimationCallback(), but none of those have worked. Thanks!

#1
04/29/2007 (11:17 am)
The ProcessList.AddAnimationCallback() is for obtaining TorqueComponent.UpdateAnimation callbacks (similar to Ticks, but you only get before rendering). I haven't used that delegate, but the normal way of using event delegate properties in C# is that you just set them to the function you want to be called. I.e

YourAnimationObject.OnAnimationEnd = YourAnimationEndFunction

All you have to do is to make sure that your function matches the delegate type, i.e. has the right parameters (check reference api or GSE tooltips).

Matias
#2
05/14/2007 (6:33 pm)
To add a delegate to a T2DAnimatedSpriteObject
//populate
T2DAnimatedSprite _player = TorqueObjectDatabase.Instance.FindObject<T2DAnimatedSprite>(_sceneObject.Name);
_player.OnAnimationEnd += new T2DAnimatedSprite.OnAnimationEndDelegate(OnAnimationEnd);

To remove:

_player.OnAnimationEnd -= new T2DAnimatedSprite.OnAnimationEndDelegate(OnAnimationEnd);

public void OnAnimationEnd()
        {
            //Stuff Here
        }
#3
05/24/2007 (9:11 am)
Matias had it right. The 'new' statement isn't neccesary.