Change Animation in Code
by Sam M · in Torque X 2D · 04/04/2007 (11:21 am) · 2 replies
I've looked around the TorqueX forums but I can't quite seem to find a thread that works for the latest release. So I'm wondering what would be the best way to change an animated sprite's animation in code. Any help would be great, thanks.
Torque Owner Thomas Buscaglia
Where myAnimatedSprite is a T2DAnimatedSprite and myAnimationData is a T2DAnimationData of the new animation you wish to be played. You can get a reference to an animated sprite or animation created in TGBX by name like so:
T2DAnimatedSprite myAnimatedSprite = TorqueObjectDatabase.Instance.FindObject<T2DAnimatedSprite>("myAnimatedThingy"); T2DAnimationData myAnimationData = TorqueObjectDatabase.Instance.FindObject<T2DAnimationData>("skippittyDoo");Where "myAnimatedThingy" is the name given to the animated sprite in TGBX and "skippittyDoo" is the name given to the animation in TGBX.