Cocos2d iphone Cocos2d CCSpeed运行中崩溃

Cocos2d iphone Cocos2d CCSpeed运行中崩溃,cocos2d-iphone,ccspeed,Cocos2d Iphone,Ccspeed,我在cocos2d iPhone游戏中使用了CCSpeed动作。但总是崩溃 CCAnimation* animation = nil; animation = [[CCAnimationCache sharedAnimationCache] animationByName:ATTACK_ANIM]; if(animation) { CCAnimate *animAction = [CCAnimate actionWithAnimation:animation]; id s

我在cocos2d iPhone游戏中使用了CCSpeed动作。但总是崩溃

CCAnimation* animation = nil;
animation = [[CCAnimationCache sharedAnimationCache]  animationByName:ATTACK_ANIM];

if(animation)
{
    CCAnimate *animAction  = [CCAnimate actionWithAnimation:animation];

    id speed = [CCSpeed actionWithAction:animAction speed:0.13f];
    id calBlock = [CCCallBlock actionWithBlock:^{
                                                    //[self updateState:kTileState_Idle];
                                                }];
    CCSequence *sequence = [CCSequence actions:speed, calBlock, nil];        
    [self runAction:sequence];
}
但下面的代码工作正常,但无法更改动画速度。上面的代码有什么问题

    CCAnimation* animation = nil;
    animation = [[CCAnimationCache sharedAnimationCache]  animationByName:quakeAnim];

    if(animation)
    {
        CCAnimate *animAction  = [CCAnimate actionWithAnimation:animation];
        id calBlock = [CCCallBlock actionWithBlock:^{
                                                        //[self updateState:kTileState_Idle];
                                                    }];
        CCSequence *sequence = [CCSequence actions:animAction, calBlock, nil];        
        [self runAction:sequence];
    }

这是一个花药。但是没有提供代码解决方案。

能否将animation.delayPerUnit设置为某个合适的值以改变其执行速度?我通常在每次使用之前计算这个数字。。。因此,在将动画放入缓存之前,我不需要保留设置的初始“delayPerUnit”

float totalAnimationTime = kSomeDesiredValue; // game logic dictates this, as well as
                                              // rendering requirements (too slow will be perceived)
animation.delayPerUnit = totalAnimationTime/animation.totalDelayUnits;

// totalDelayUnits is a property of the animation, usually equal to the number
// of frames.
你做错了

CCSpeed不能按顺序使用。您仍然需要将动画动作添加到序列中,但保留对CCSpeed动作(ivar)的引用。然后,无论何时要更改动画速度,请更改CCSpeed实例的“速度”属性


使用CCSped需要适当地管理序列内存和CCSpeed。

加载delayPerUnit后,我们无法更改它。我需要随着游戏的进行动态地改变动画的速度。这个属性不是只读的,所以你可以在游戏中改变它。如果您担心并发性(多个实例),请复制缓存动画并更改副本上的delayPerUnit,然后运行copy.not getting..请给我一个代码示例(使用CCSpeed)。在网上搜索但没有用。