cocos2d中如何计算动画的时间间隔?

发布于 2024-08-27 09:12:37 字数 178 浏览 5 评论 0原文

我正在 cocos2d 中做我的程序。 我正在使用 NSDate 来获取动画开始的当前时间。我知道我的动画需要 3 秒。因此,我可以通过使用 NSInterval 并使用前一个时间和动画时间来获取动画完成的时间。但是,如果动画时间间隔不固定,我如何计算动画的时间间隔和动画完成的时间?我正在制作一个精灵的动画。请帮助我怎样才能做到。 谢谢。

I am doing my program in cocos2d.
I am using NSDate to get the current time of the start of animation. And I know my animation takes 3 seconds. So I can get the time at completion of animation by using NSInterval and using the previous time and animation time. But, if If the animation time interval is not fixed how can I calculate the time interval of the animation and time at the completion of the animation ? I am animating a sprite. Please help how can I make it.
Thank You.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

深空失忆 2024-09-03 09:12:37

CCIntervalAction 类有一个名为 elapsed 的属性,它以 ccTime 的形式提供自操作开始以来已过去的秒数。由于 CCAnimate 操作派生自 CCIntervalAction,因此您应该有权访问此属性。

CCAnimation *myAnimation = [CCAnimation animationWithName:@"my animation" delay:0.1f];
CCAnimate *myAnimateAction = [CCAnimate actionWithAnimation:myAnimation];
[sprite runAction:myAnimateAction];
...
ccTime interval = myAnimateAction.elapsed;

The CCIntervalAction class has a property called elapsed that gives you the number of seconds that have elapsed since the action started as a ccTime. Since the CCAnimate action derives from CCIntervalAction, you should have access to this property.

CCAnimation *myAnimation = [CCAnimation animationWithName:@"my animation" delay:0.1f];
CCAnimate *myAnimateAction = [CCAnimate actionWithAnimation:myAnimation];
[sprite runAction:myAnimateAction];
...
ccTime interval = myAnimateAction.elapsed;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文