Need to reverse animation

Discussion and feedback on Construct 2

Post » Wed Aug 22, 2012 9:27 pm

I have a player that leans to the left or right based on the arrow keys. There are 9 frames with 4 being the default position when no arrow is down. I would like to animate from left to right or right to left seamlessly without having to use multiple animations.But there is no way to animate in reverse that I've seen.

I've noticed that there is a ping pong behavior for animations, but that's not completely what I'm looking for. Would be nice if I could animation from frame 0-5, 0-9, 5-0 based on need. I think the ability to have frame labels would be nice as well so you don't have to rely on numbers always.

Is there a way to do this currently?

Thanks for considering!
B
14
S
5
G
2
Posts: 20
Reputation: 2,378

Post » Wed Aug 22, 2012 10:40 pm

You could set the animation speed to 0 and animate manually via events.

when the player holds left
+every 0.2 seconds ---> set current frame to: max(currentFrame-1,0)

when the player holds right
+every 0.2 seconds ---> set current frame to: min(currentFrame+1,9)

when the player not holding left or right, add 1 if the current frame is <4 and subtract if the current frame is >4

assuming your animation is somewhat like this: _\|/_

you may need to tweak the "every 0.2 seconds" to speed up or slow down your animation.Fimbul2012-08-22 23:29:27
B
36
S
8
G
8
Posts: 532
Reputation: 6,903

Post » Wed Aug 22, 2012 10:44 pm

Yeah was missing this feature a few weeks back.
Your other option is to duplicate the animation, and reverse the order.
Might put in a request to @Ashley
If its not in his to do list already.
Image ImageImage
B
165
S
49
G
146
Posts: 8,038
Reputation: 96,066

Post » Thu Dec 29, 2016 4:00 am

I know this is an old post.

I was looking for this, I had the same question.
I typed out my questions and everything, I even posted them.
I then I realized the solution, so I edited this to give it.

You have to reverse the play speed of the animation.
I have my speed set to a Variable.
So when I need to reverse an animation I did this.

Set animation speed to -abs(SpeedVariable)

abs is "Absolute Value". It is a mathematical expression.

What it does is turn negative numbers positive.
So if you have a declining slope like this:
3, 2, 1, 0, -1, -2, -3

Using abs() will give you:
3, 2, 1, 0, 1, 2, 3

By putting a "-" in front of abs() it makes every number negative, like this:
-3, -2, -1, 0, -1, -2, -3

Therefore it reverses the animation speed.

You can then use Conditions
"Compare frame", "Compare speed", and "Is playing" to do what you need.

* Zero will always be 0. Zero can't be negative nor positive*
B
52
S
31
G
13
Posts: 210
Reputation: 11,688


Return to Construct 2 General

Who is online

Users browsing this forum: tetuan and 6 guests