如何在 IMPACTJS 中反转动画
我正在使用 ImpactJS 在 HTML5 和 JS 上创建游戏,当动画运行时,是否可以在任何帧反转动画帧流(而不是翻转)?我用了rewind(),它只能回到第一帧,有没有reverse()?
i am using ImpactJS to create a game on HTML5 and JS, when a animation is running, is it possble at any frame to reverse the animation frame flow (not flipping) ? I used rewind(), it only gets back to the first frame, is there any reverse()?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您不介意有点hacky,那么从理论上讲,这样的事情应该可以工作:
基本上,
ig.Animation()
类的序列属性决定了帧的运行顺序, update 只是根据计时器迭代它们。反转它,你就反转了动画。当您想要将动画重置为向前时,您可以再次使用相同的代码。如果您希望播放完整的反向动画,您可能还需要执行
animation.rewind()
而不是gotoFrame()
。否则,您可以使用 2 个动画,并在切换动画时使用
gotoFrame()
来启动正确的帧。另请注意,上面的代码将复制一帧动画,您需要删除-1
(查看源代码,我认为在frame = 0 的情况下这没问题)。
If you don't mind being a bit hacky something like this should, in theory, work:
Basically the sequence property of the
ig.Animation()
class is what determines the order the frames are run, the update just iterates over them based on a timer. Reverse that and you reverse the animation. You can just use the same code again when you want to reset the animation to be forward.You may need to also do
animation.rewind()
instead ofgotoFrame()
if you want the full reversed animation to play out.Otherwise you could use 2 animations and use
gotoFrame()
when switching animations to start the correct frame. Also of note the code above will duplicate one frame of animation, you'd want to remove the-1
(looking at the source I think this will be okay in the case whereframe = 0
).不,但是您可以使用插件系统轻松编写自己的系统。
或者只是从enetity.currentAnim.frame开始创建一个新动画,然后通过entity.sequence向后工作。然后将当前动画设置为新动画。
No, but you could easily write your own using the plugin system.
Or just create a new animation starting with the enetity.currentAnim.frame and then working backwards through entity.sequence.Then setting the current animation to the new one.
不,我知道没有反转
,但你可以创建具有反转序列的新动画
然后在需要的地方切换到该动画
No there isn't reverse that i knew of
but instead you could just create new animation that has reversed sequence
then switch to that animation wherever needed