cocos2d的动态变化的动画速度CCSpeed [英] cocos2d dynamically changing animation speed with CCSpeed

查看:135
本文介绍了cocos2d的动态变化的动画速度CCSpeed的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个简单的游戏,一个人物有大约15帧的动画行走。基于所述加速度计是速度沿任一方向改变。我想动画加快或相应放慢。我意识到,一旦动画被初始化,则不能更改延迟速度,而是你需要创建一个新的动画。但由于转速变化几乎不断,如果我一直在CH375复位动画,它总是被卡住在同一框架上。

In a simple game, a character has a walking animation of around 15 frames. Based on the accelerometer is speed in either direction changes. I wanted the animation to speed up or slow down accordingly. I realize that once the animation is initialized, you can't change the delay speed, and instead you need to create a new animation. But since the speed changes almost constantly, if I kept reseting the animation, it would always be stuck on the same frame.

有没有办法找出哪一帧动画,目前在,停止它,然后创建一个新的动画用相同的框架,但开始时的最后一个动画结束?

否则没有任何人有你怎么可能去实现一个动态变化的动画延迟时间的想法?

Otherwise does anybody have an idea of how you could go about implementing a dynamically changing animation delay time?

编辑:

我一直在使用CCSpeed​​要做到这一点,从一个例子中学习了cocos2d 2.这里是code尝试:

I have tried using CCSpeed to do this from an example in Learn Cocos2d 2. Here is the code:

    CCRepeatForever *walkLeftRepeat = [CCRepeatForever actionWithAction:[CCAnimation animationWithSpriteFrames:walkLeftFrames]];

    self.walkLeft = [CCSpeed actionWithAction:walkLeftRepeat speed:animationWalkingSpeed];

我得到以下警告:不兼容的指针类型发送'CCRepeatForever *为类型的参数CCActionInterval *

I get the following warning: Incompatible pointer types sending 'CCRepeatForever *' to parameter of type 'CCActionInterval *'

下面是我从下面的例子:

Here is the example I am following from:

    CCRepeatForever* repeat = [CCRepeatForever actionWithAction:rotateBy];
    CCSpeed* speedAction = [CCSpeed actionWithAction:repeat speed:0.5f];

第二个编辑:

然后我尝试这样的:

    CCAnimation *walkLeftRepeat = [CCAnimation animationWithSpriteFrames:walkLeftFrames];
    CCAnimate *temp = [CCAnimate actionWithAnimation:walkLeftRepeat];
    CCAnimate*temp2 = [CCRepeatForever actionWithAction:temp];
    self.walkLeft = [CCSpeed actionWithAction:temp2 speed:animationWalkingSpeed];
    [_guy runAction:_walkLeft];

最后编辑。它没有显示出来此问题已修复通过添加延迟ccanimation。

Final edit. This problem of it not showing up was fixed by adding a delay to ccanimation.

这不会给任何错误的,但没有任何反应。
谢谢!

This doesn't give any error's but nothing happens. Thanks!

推荐答案

没有必要重新创建动画。使用CCSpeed​​行动的CCAnimate行动,其内部的行动。然后,你可以修改CCSpeed​​动作的速度属性来加快或减慢动画。

No need to recreate the animation. Use a CCSpeed action with the CCAnimate action as its inner action. Then you can modify the CCSpeed action's speed property to speed up or slow down the animation.

另一种方法是自己前进的帧。这很容易做到,你只需要一个预定的更新,并且告诉您何时切换到下一帧的计时器。你加快或通过简单地改变你多么添加到计时器每帧减慢动画。如果计时器>大于特定值更改框架和定时器重置为0。

The alternative is to advance frames yourself. It's easy to do, you only need a scheduled update and a timer that tells you when to change to the next frame. You speed up or slow down the animation by simply changing how much you add to the timer every frame. If the timer is > than a specific value you change frames and reset the timer to 0.

这篇关于cocos2d的动态变化的动画速度CCSpeed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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