Game Development Community

Playing an animation in reverse

by Doug Barnes · in Torque X 2D · 12/13/2007 (9:34 am) · 5 replies

Hello Everyone,

I was wondering if it is possible to play an animation in reverse, so instead of increasing in frames they decrease. This seems like it would be an easy thing to do but I cant find a way to do it. Also if there currently isn't a way to play animations like this does anyone know where the hypothetical "AdvanceFrame" method would be so I could add this functionality in myself? By the way making a new animation and having the frames inverted is not what I'm looking for here.

Thanks in advance,
Doug

#1
12/14/2007 (5:14 pm)
Hi,

This will play an animation in reverse.

guy.AnimationData.AnimationFramesList.Reverse();
guy.PlayAnimation();

Where guy is a T2DAnimatedSprite. The animation starts over from the new beginning though.

Whats wrong with using two animations, one forward and one in reverse?
#2
02/06/2008 (8:24 pm)
I really think there should be a simple PlayAnimationInReverse method for this, since it seems like a common thing to do. However, since the play in reverse method doesn't exist, what is the proper method to copy an animation and reverse it?

My naive first attempt did not work:

reverseAnimation_ = new T2DAnimationData();
originalAnimation_.CopyTo(reverseAnimation_);
reverseAnimation_.AnimationFramesList.Reverse();

This caused the originalAnimation_ to be reversed too. I guess CopyTo is a shallow copy?
#3
02/07/2008 (7:23 pm)
My second equally unsuccessful attempt was:

reverseAnimation_ = originalAnimation_.Clone() as T2DAnimationData;

This gave me an assertion failure:

"T2DAnimationData.CopyTo(TorqueObject obj) needs the following lines of code:

T2DAnimationData obj2 = (T2DAnimationData)obj;
obj2.AnimationCycle = AnimationCycle;"

I have a large number of animations that I need to reverse. There has to be a way to do this other than manually creating them all in TXB.
#4
02/08/2008 (9:18 am)
I tested with my own code below:

// Get the T2dAnimationData
                T2DAnimationData newAnimationData = AnimationManager.Instance.CreateT2DAnimationData(configuration);
                // Play the new animation

                T2DAnimationData test1 = new T2DAnimationData();
                newAnimationData.CopyTo(test1);
                test1.AnimationFramesList.Reverse();
                _sprite.PlayAnimation(newAnimationData);

I checked the animationFrameslist before and after for both newanimationdata and the test1 one. The test1 was reversed, but the original still had its regular values. Just throwing some thought out, is the poolable flag set to true or false? I believe after digging through the code it tries to find it in the object pool. My test above both were false. I wonder if you set the Pool to false on the original, what would happen. Just some thoughts.
#5
02/09/2008 (7:42 am)
Pool is false on both objects.

I got the code to work by adding a call to Init().

reverseAnimation_ = new T2DAnimationData();
originalAnimation_.CopyTo(reverseAnimation_);
reverseAnimation_.Init();
reverseAnimation_.AnimationFramesList.Reverse();

I inspected the object after the call to CopyTo an noticed that the initialized property was false. That's why I decided to try calling Init().

Many more of these and I'll have to buy the Pro version to get the documentation; er, I mean source code. :)