CCSpeed用于线性地改变某个动作的速度,因此,可以实现成倍地快放或慢放功能。为了改变一个动作的速度,首先需要将目标动作包装到CCSpeed动作中:


看个例子代码:

CCSpriteFrameCache *cache = CCSpriteFrameCache::sharedSpriteFrameCache();
        cache->addSpriteFramesWithFile("animations/grossini.plist", "animations/grossini.png");
        CCArray *amationArray = CCArray::create();
        char str[100];
        for(int i = 1; i < 15; ++i) {
            sprintf(str, "grossini_dance_%02d.png", i);
            amationArray->addObject(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(str));
        }
        CCAnimation *palyer = CCAnimation::create(amationArray, 0.5f);
        CCSprite *sprite1 = CCSprite::create("grossini.png");
        sprite1->setAnchorPoint(ccp(0.5f, 0.5f));
        sprite1->setPosition(ccp(size.width / 2.0f, size.height / 2.0f - 100 ));
        this->addChild(sprite1, 1);



添加动画帧。


产生动画:

CCAnimation *palyer = CCAnimation::create(amationArray, 0.5f);//设置当前帧
        CCSprite *sprite1 = CCSprite::create("grossini.png");
        sprite1->setAnchorPoint(ccp(0.5f, 0.5f));
        sprite1->setPosition(ccp(size.width / 2.0f, size.height / 2.0f - 100 ));
        this->addChild(sprite1, 1);




CCRepeatForever *repeat = CCRepeatForever::create(CCAnimate::create(palyer));
        CCSpeed *speed = CCSpeed::create(repeat, 4.0f);//第二个参数是每个动作的速度,值越大,速度越快。
        sprite1->runAction(speed);