我如何获得帧的指数在动画 [英] How do I get the index of frame in a animation

查看:238
本文介绍了我如何获得帧的指数在动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在与SpriteKit一场比赛中斯威夫特,并使用animateWithTextures()来为不同的举动动画。现在的问题是如何获取当前帧的指数在动画之前结束?
为什么我需要获得ID的原因是因为有时我需要取消它的行动完成之前,但不会太早。例如,我有一个动作包含10帧,玩家只能框架6之后取消行动?此外,我以后可能会使用框架检查动画的过程也是如此。

I'm currently making a game with SpriteKit in Swift, and using animateWithTextures() to make animation for different move. Now my question is how do I get the index of current frame in a animation before it ends? The reason why I need to get the ID is because sometimes I need to cancel an action before it finished but not too early. For example, I have a action contain 10 frames, player can cancel that action only after frame 6? Also I might use the frame later for check the animation's process as well.

推荐答案

您可以做这样的事情:

        if String(yourSprite.texture).rangeOfString("frameImageName") != nil {
            //code to stop animation 
            }

所以,如果你把这块code的更新函数内帧需要检查每一个函数被调用时,你可以轻松地在正确的点停止动画。

So if you put this piece of code inside the update function the frames get checked every time the function gets called and you can easily stop the animation at the right point.

这篇关于我如何获得帧的指数在动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆