2014年10月29日 星期三

[Spine] 動作進入Runtimes時,發生動作互相干擾的問題

使用Spine應該都會遇到一個狀況,就是A動作結束之後進入B動作,卻發現B動作的某些骨頭的動態有問題,看起來是受到A動作干擾,這是因為Spine的設計是當該Track不帶有Keyframes時,就會延續上一個動作的資訊!所以解決方式就是在動作的起始幀對每一個Track上Key。

詳見官網文件:
http://esotericsoftware.com/spine-using-runtimes#Animation-changes
An animation only affects the bones and slots for which it has keyframes.
When animations are applied in sequence, a previous animation may have made changes to bones or slots that a subsequent animation does not have keyframes for.
This can be solved be keying everything at the start of the second animation that the first animation affects.
文件有提到對每個Track打上key是會造成額外的運算負擔,但若是增加的幅度很小,其實也可以無視了。
With many animations this quickly leads to everything being keyed at the start of every animation. This is suboptimal because each property that is keyed adds a small amount of overhead when the animation is applied each frame.
文件也提出第二種解決方式,就是歸回SetupPose,但造成的負面影響是動作可能會發生不順暢、無法crossfading的狀況。 
Another solution is to call setToSetupPose, setBonesToSetupPose, or setSlotsToSetupPose on the skeleton when the current animation is changed (or otherwise write code that changes the slots and bones as needed).
However, this will cause bones that aren't keyed in the second animation to be instantly set to the setup pose state. AnimationState won't be able to do crossfading for those bones.

[Spine] 熱鍵