I've seen multiplay old threads that his is not possible yet, so I'm here to ask if there's a way now to play animations backwards?
Cocos2d-x Play Animation in reverse / backwards
- 編集済み
Instead of using AnimationState, which doesn't support reverse playback, you can use the Animation API to pose the skeleton. See spAnimation_apply
.
Nate wroteInstead of using AnimationState, which doesn't support reverse playback, you can use the Animation API to pose the skeleton. See
spAnimation_apply
.
Hello, Nate.
I've been used spAnimation_apply
to play my animations back and forward until switched to Spine v 3.5.x. And now many *Timeline_apply(...)
trying to interpolate between previous frame in constant frameline which make backward playback impossible. Maybe there is another way to work it around ? Thanks in advance for reply.
Found this:
badlogic wroteWe currently don't support backwards playback at runtime via AnimationState.
Creating a separate animation by copying and reverting the keys of the forward animation is currently your best option.
In my opinion it might be not a best solution:
- More work for artists
- Double animation for same thing is a potential bug source
- More id's to manage (state1_action1_normal, state1_action1_reversed, state1_action2_normal ...)
roman_dev wrotenow many *Timeline_apply(...) trying to interpolate between previous frame in constant frameline which make backward playback impossible.
Can you give an example of a timeline that doesn't work when playing backward? The Timeline API should just pose the skeleton at the requested frame. Most of the timelines don't care whether the frames you are posing are changing forward of backward over time. Only EventTimeline cares, because it makes use of the lastTime
parameter for what it needs to do.
Nate, thanks for answer
For example, saw this in RotateTimeline :
prevRotation = self->frames[frame + ROTATE_PREV_ROTATION];
where
ROTATE_PREV_ROTATION = -1
If I got it wrong and it's not a value inside of a previous frame, but a value stored in a current frame ... uh, that still doesn't makes things work (but they did before), unfortunately. I also used spAnimation_apply
to "split" long animation into short pieces and play them with different easings (including elastic) not involving setAnimation(...)
call (and autoupdate as a result) . What might be my best option for this now ?
When posing a skeleton using an animation for a particular time, we have to find the key before the time and the key after the time, then we can interpolate between the two key values. That is what the prevRotation
is about.
I need to understand exactly what doesn't work before I can suggest how to solve the problem. Can you explain more about what isn't working?
Nate wroteCan you explain more about what isn't working?
Sure. When spine animation loaded I get several animations from it via spSkeletonData_findAnimation
and then, accordingly to different game events, running custom update which invoking spAnimation_apply(anim, skeleton, 0, animTime, 0, events, &eventsCount, 1.0f, 1, 0)
. I did some experiments today and found out that this code stops working after first setAnimation
call and spAnimationState_clearTracks
before applying custom-update seems to be fixing it. It's just seems a bit strange: animation invoked by setAnimation
is finished at the moment of apply
call.
You said you use spAnimation_apply
, but then mentioned AnimationState methods. AnimationState cannot play backwards (and never could).