• <small id='nQH2L'></small><noframes id='nQH2L'>

          <bdo id='nQH2L'></bdo><ul id='nQH2L'></ul>
        <tfoot id='nQH2L'></tfoot>
        <legend id='nQH2L'><style id='nQH2L'><dir id='nQH2L'><q id='nQH2L'></q></dir></style></legend>
        <i id='nQH2L'><tr id='nQH2L'><dt id='nQH2L'><q id='nQH2L'><span id='nQH2L'><b id='nQH2L'><form id='nQH2L'><ins id='nQH2L'></ins><ul id='nQH2L'></ul><sub id='nQH2L'></sub></form><legend id='nQH2L'></legend><bdo id='nQH2L'><pre id='nQH2L'><center id='nQH2L'></center></pre></bdo></b><th id='nQH2L'></th></span></q></dt></tr></i><div id='nQH2L'><tfoot id='nQH2L'></tfoot><dl id='nQH2L'><fieldset id='nQH2L'></fieldset></dl></div>

        cocos2d 使用 CCSpeed 动态改变动画速度

        时间:2024-08-12

          • <small id='E93ir'></small><noframes id='E93ir'>

            1. <i id='E93ir'><tr id='E93ir'><dt id='E93ir'><q id='E93ir'><span id='E93ir'><b id='E93ir'><form id='E93ir'><ins id='E93ir'></ins><ul id='E93ir'></ul><sub id='E93ir'></sub></form><legend id='E93ir'></legend><bdo id='E93ir'><pre id='E93ir'><center id='E93ir'></center></pre></bdo></b><th id='E93ir'></th></span></q></dt></tr></i><div id='E93ir'><tfoot id='E93ir'></tfoot><dl id='E93ir'><fieldset id='E93ir'></fieldset></dl></div>

                <legend id='E93ir'><style id='E93ir'><dir id='E93ir'><q id='E93ir'></q></dir></style></legend>
                  <bdo id='E93ir'></bdo><ul id='E93ir'></ul>
                • <tfoot id='E93ir'></tfoot>

                    <tbody id='E93ir'></tbody>
                  本文介绍了cocos2d 使用 CCSpeed 动态改变动画速度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在一个简单的游戏中,一个角色有一个大约 15 帧的行走动画.基于加速度计的是速度在任一方向的变化.我希望动画相应地加速或减速.我意识到一旦动画被初始化,你就不能改变延迟速度,而是需要创建一个新的动画.但是由于速度几乎是不断变化的,如果我一直重置动画,它总是会卡在同一帧上.

                  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?

                  我在 Learn Cocos2d 2 中的一个示例中尝试使用 CCSpeed 来执行此操作.代码如下:

                  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 *'

                  这是我所遵循的示例:

                  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];
                  

                  最终编辑.通过添加动画延迟来解决它不显示的问题.

                  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!

                  推荐答案

                  无需重新创建动画.使用带有 CCAnimate 动作的 CCSpeed 动作作为其内部动作.然后你可以修改 CCSpeed 动作的 speed 属性来加快或减慢动画的速度.

                  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 动态改变动画速度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在 cocos2d 中添加 UIViewController 下一篇:ccDrawLine 不透明度?

                  相关文章

                    <legend id='FxYoC'><style id='FxYoC'><dir id='FxYoC'><q id='FxYoC'></q></dir></style></legend>

                    <small id='FxYoC'></small><noframes id='FxYoC'>

                      <bdo id='FxYoC'></bdo><ul id='FxYoC'></ul>

                      <tfoot id='FxYoC'></tfoot>

                      <i id='FxYoC'><tr id='FxYoC'><dt id='FxYoC'><q id='FxYoC'><span id='FxYoC'><b id='FxYoC'><form id='FxYoC'><ins id='FxYoC'></ins><ul id='FxYoC'></ul><sub id='FxYoC'></sub></form><legend id='FxYoC'></legend><bdo id='FxYoC'><pre id='FxYoC'><center id='FxYoC'></center></pre></bdo></b><th id='FxYoC'></th></span></q></dt></tr></i><div id='FxYoC'><tfoot id='FxYoC'></tfoot><dl id='FxYoC'><fieldset id='FxYoC'></fieldset></dl></div>