如何在 IMPACTJS 中反转动画

发布于 2024-12-20 00:16:07 字数 104 浏览 2 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

伊面 2024-12-27 00:16:07

如果您不介意有点hacky,那么从理论上讲,这样的事情应该可以工作:

animation.sequence = animation.sequence.reverse(); //Reverse the animation
animation.gotoFrame(animation.length - animation.frame - 1); //Set the frame to be the same frame as it was before.

基本上,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:

animation.sequence = animation.sequence.reverse(); //Reverse the animation
animation.gotoFrame(animation.length - animation.frame - 1); //Set the frame to be the same frame as it was before.

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 of gotoFrame() 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 where frame = 0).

遮云壑 2024-12-27 00:16:07

不,但是您可以使用插件系统轻松编写自己的系统。

或者只是从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.

抚笙 2024-12-27 00:16:07

不,我知道没有反转

,但你可以创建具有反转序列的新动画
然后在需要的地方切换到该动画

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文