当前位置: 首页>>代码示例>>C++>>正文


C++ CCAnimation::addSpriteFrame方法代码示例

本文整理汇总了C++中CCAnimation::addSpriteFrame方法的典型用法代码示例。如果您正苦于以下问题:C++ CCAnimation::addSpriteFrame方法的具体用法?C++ CCAnimation::addSpriteFrame怎么用?C++ CCAnimation::addSpriteFrame使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CCAnimation的用法示例。


在下文中一共展示了CCAnimation::addSpriteFrame方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: slowDown

void Planet::slowDown()
{
	// 当前的逻辑禁止在一个减速期间叠加另一个减速
	if(m_bSlowDowned)
		return;

	m_bSlowDowned = true;	

	if(!m_pSlowDownMark)
	{
		setSlowDownMark(CCSprite::create());
		m_pSlowDownMark->setPosition(ccp(113,65));
		this->addChild(m_pSlowDownMark);
	}

	m_pSlowDownMark->setVisible(true);	

	CCSpriteFrameCache* cache = CCSpriteFrameCache::sharedSpriteFrameCache();
	cache->addSpriteFramesWithFile("SlowDownMark.plist");
	CCAnimation* animation = CCAnimation::create();
	animation->addSpriteFrame(cache->spriteFrameByName("SlowDownMark_0.png"));	
	animation->addSpriteFrame(cache->spriteFrameByName("SlowDownMark_1.png"));	
	animation->addSpriteFrame(cache->spriteFrameByName("SlowDownMark_2.png"));	
	animation->addSpriteFrame(cache->spriteFrameByName("SlowDownMark_3.png"));	
	animation->addSpriteFrame(cache->spriteFrameByName("SlowDownMark_4.png"));	
	animation->addSpriteFrame(cache->spriteFrameByName("SlowDownMark_4.png"));
	animation->setDelayPerUnit(0.2f);
	CCAnimate* animate = CCAnimate::create(animation);
	m_pSlowDownMark->runAction(CCRepeatForever::create(animate));	

	this->scheduleOnce(schedule_selector(Planet::slowDownRestore) , SLOW_DOWN_DURATION);

	if(m_pFace)
		m_pFace->cry();
}
开发者ID:daoduchai,项目名称:DogsMustDie,代码行数:35,代码来源:Planet.cpp

示例2: birdReadyAction

void GameScene::birdReadyAction()
{
    CCSize winSize =CCDirector::sharedDirector()->getWinSize();
    // 添加bird精灵
    CCSprite *bird =CCSprite::createWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("bird1.png"));
    bird->setPosition(ccp(winSize.width/2-80,winSize.height/2+20));
    bird->setZOrder(20);
    bird->setScale(0.6);
    bird->setTag(TAG_BIRD);
    bird->setVisible(false);
    this->addChild(bird);
    // 创建动画对象
    CCAnimation *birdAnimation =CCAnimation::create();
    birdAnimation->setDelayPerUnit(0.2);
    birdAnimation->addSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("bird1.png"));
    birdAnimation->addSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("bird2.png"));
    birdAnimation->addSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("bird3.png"));
    // 创建动画动作
    birdanimate =CCAnimate::create(birdAnimation);
    CCActionInterval *action =CCMoveBy::create(0.2,ccp(0,10));
    CCActionInterval *action1 =action->reverse();
    CCActionInterval *sequence =CCSequence::create(action,action1,NULL);
    CCSpawn *spawn =CCSpawn::create(sequence,birdanimate,NULL);
    CCRepeatForever *birdrepeatForever =CCRepeatForever::create(spawn);
    // 让bird精灵一直运行动画
    bird->runAction(birdrepeatForever);
}
开发者ID:ToanLe123,项目名称:angrybird,代码行数:27,代码来源:GameScene.cpp

示例3: createActions

void GameLayer::createActions() {
    
    // Swing action for health drops
    CCFiniteTimeAction* easeSwing = CCSequence::create(CCEaseInOut::create(CCRotateTo::create(1.2f, -10), 2),
                                                       CCEaseInOut::create(CCRotateTo::create(1.2f, 10), 2),
                                                       NULL);
    
    _swingHealth = CCRepeatForever::create((CCActionInterval*)easeSwing);
    _swingHealth->retain();
    
    // Action sequence for shockwave : fade out, callback when done
    _shockwaveSequence = CCSequence::create(CCFadeOut::create(1.0f),
                                            CCCallFunc::create(this, callfunc_selector(GameLayer::shockwaveDone)),
                                            NULL);
    _shockwaveSequence->retain();
    
    // Action to grow bomb
    _growBomb = CCScaleTo::create(6.0f, 1.0);
    _growBomb->retain();
    
    // Action to rotate sprites
    CCActionInterval* rotate = CCRotateBy::create(0.5f, -90);
    _rotateSprite = CCRepeatForever::create(rotate);
    _rotateSprite->retain();
    
    // Animations
    CCAnimation* animation = CCAnimation::create();
    for (int i = 1; i <= 10; ++ i)
    {
        CCString* name = CCString::createWithFormat("boom%i.png", i);
        CCSpriteFrame* frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(name->getCString());
        animation->addSpriteFrame(frame);
    }
    
    animation->setDelayPerUnit(1 / 10.0f);
    animation->setRestoreOriginalFrame(true);
    _groundHit = CCSequence::create(CCMoveBy::create(0, ccp(0, _screenSize.height * 0.12f)),
                                    CCAnimate::create(animation),
                                    CCCallFuncN::create(this, callfuncN_selector(GameLayer::animationDone)),
                                    NULL);
    _groundHit->retain();
    
    
    animation = CCAnimation::create();
    for (int i = 1; i <=7; ++ i)
    {
        CCString* name = CCString::createWithFormat("explosion_small%i.png", i);
        CCSpriteFrame* frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(name->getCString());
        animation->addSpriteFrame(frame);
    }
    
    animation->setDelayPerUnit(0.5 / 7.0f);
    animation->setRestoreOriginalFrame(true);
    _explosion = CCSequence::create(CCAnimate::create(animation),
                                    CCCallFuncN::create(this, callfuncN_selector(GameLayer::animationDone)),
                                    NULL);
    _explosion->retain();

}
开发者ID:ivanchenhz,项目名称:IvanChenGit,代码行数:59,代码来源:GameLayer.cpp

示例4: setupAnimations

void Player::setupAnimations()
{

    CCAnimation* animation;
    CCSpriteFrame * frame;
    
    //create CCAnimation object
    animation = CCAnimation::create();
    //CCString * name;
    
    frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("reload.png");
    animation->addSpriteFrame(frame);
    frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("reloadready.png");
    animation->setDelayPerUnit(.5 / 2.0f);
    animation->setRestoreOriginalFrame(false);
    _cannotReload = CCSequence::create(
                                 CCAnimate::create(animation),
                                 CCCallFuncN::create(this, callfuncN_selector(Player::canReloadAnimationDone)),
                                 NULL);
    _cannotReload->retain();
    
    animation = CCAnimation::create();
    frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("reloadready.png");
    animation->addSpriteFrame(frame);
    frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("reload.png");
    animation->setDelayPerUnit(.5 / 2.0f);
    animation->setRestoreOriginalFrame(false);
    _canReload = CCSequence::create(
                                    CCAnimate::create(animation),
                                    CCCallFuncN::create(this, callfuncN_selector(Player::cannotReloadAnimationDone)),
                                    NULL);
    _canReload->retain();
    
    //create CCAnimation object
    animation = CCAnimation::create();
    CCString * name;
    for(int i = 0; i <= 20; i++) {
        name = CCString::createWithFormat("shell%i.png", i);
        frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(name->getCString());
        animation->addSpriteFrame(frame);
    }
    
    animation->setDelayPerUnit(.5 / 21.0f);
    animation->setRestoreOriginalFrame(false);
    animation->setLoops(10);
    _rotateShells = CCSequence::create(
                                 CCAnimate::create(animation),
                                 CCCallFuncN::create(this, callfuncN_selector(Player::shellAnimationDone)),
                                 NULL);
    _rotateShells->retain();
    
}
开发者ID:xgeraldx,项目名称:ETMG-Week2-3,代码行数:52,代码来源:Player.cpp

示例5: addCap

void CArmySprite::addCap(void)
{
	m_pCapSprite = CCSprite::create();
	m_pCapSprite->setPosition(ccp(getContentSize().width * 0.5f, getContentSize().height * 0.5f));
	addChild(m_pCapSprite);
	CCAnimation *pAnimation = CCAnimation::create();

	char szName[128] = {0};
	//sprintf(szName, "%s%02d-%02d_0001.png", m_cName, m_sCurData.mAction, m_sCurData.mDirection);

	for (int i=0; i<ANIMATE_MAX; i++)
	{
		sprintf(szName, "%s%02d_%02d.png", "NPC_Tank", m_sCurData.mIndex, 10 + i);
		if (m_pCurCache->spriteFrameByName(szName) == NULL)
		{
			break;
		}
		pAnimation->addSpriteFrame(m_pCurCache->spriteFrameByName(szName));
	}


	pAnimation->setDelayPerUnit(0.2f);
	pAnimation->setRestoreOriginalFrame(true);

	CCAnimate *pAnimate = CCAnimate::create(pAnimation);
	CCCallFunc* pCallback = CCCallFunc::create(this, callfunc_selector(CArmySprite::openCapCall));
	CCActionInterval* pAction = (CCActionInterval*)(CCSequence::create( pAnimate,pCallback,NULL) );
	m_pCapSprite->runAction(pAction);
}
开发者ID:342261733,项目名称:cocos2d-x,代码行数:29,代码来源:ArmySprite.cpp

示例6: runEffect

void CArmySprite::runEffect(void)
{
	CCAnimation *pAnimation = CCAnimation::create();

	char szName[128] = {0};
	//sprintf(szName, "%s%02d-%02d_0001.png", m_cName, m_sCurData.mAction, m_sCurData.mDirection);

	for (int i=0; i<ANIMATE_MAX; i++)
	{
		sprintf(szName, "Explode02_%02d.png", i+1);
		if (m_pCurCache->spriteFrameByName(szName) == NULL)
		{
			break;
		}
		pAnimation->addSpriteFrame(m_pCurCache->spriteFrameByName(szName));
	}


	pAnimation->setDelayPerUnit(0.1f);
	pAnimation->setRestoreOriginalFrame(true);

	CCAnimate *pAnimate = CCAnimate::create(pAnimation);
	CCCallFunc* pCallback = CCCallFunc::create(this, callfunc_selector(CArmySprite::removeSelf));
	CCActionInterval* pAction = (CCActionInterval*)(CCSequence::create( pAnimate,pCallback,NULL) );
	m_pEffectSprite->runAction(pAction);
}
开发者ID:342261733,项目名称:cocos2d-x,代码行数:26,代码来源:ArmySprite.cpp

示例7: rand

void EnemyLayer::addEnemy1(float dt){
    Enemy* enemy1 = Enemy::create();
    CCAnimation *animation;
    CCAnimate* animate;
    int enemyType = rand()%3;
    switch (enemyType) {
        case 0:
            enemy1->bindSprite(CCSprite::createWithSpriteFrame(enemy1SpriteFrame),Level1, ENEMY_MAX_LIFE1);
            break;
        case 1:
            enemy1->bindSprite(CCSprite::createWithSpriteFrame(enemy2SpriteFrame),Level2, ENEMY_MAX_LIFE2);
            break;
        case 2:
            enemy1->bindSprite(CCSprite::createWithSpriteFrame(enemy3SpriteFrame_1),Level3, ENEMY_MAX_LIFE3);
            animation = CCAnimation::create();
            animation->setDelayPerUnit(0.2f);
            animation->addSpriteFrame(enemy3SpriteFrame_1);
            animation->addSpriteFrame(enemy3SpriteFrame_2);
            animate = CCAnimate::create(animation);
            enemy1->getSprite()->runAction(CCRepeatForever::create(animate));
            break;
        default:
            enemy1->bindSprite(CCSprite::createWithSpriteFrame(enemy1SpriteFrame),Level1, ENEMY_MAX_LIFE1);
            break;
    }
    this->addChild(enemy1);
    m_pAllEnemy1->addObject(enemy1);
    CCSize enemy1Size = enemy1->getContentSize();
    CCSize winSize = CCDirector::sharedDirector()->getWinSize();
    int minX = enemy1Size.width/2;
    int maxX =winSize.width -minX;
    int rangeX = maxX - minX;
    int aclX = (rand()%rangeX) + minX;
    enemy1->setPosition(ccp(aclX, winSize.height+enemy1Size.height));
    float minDuration,maxDuration;
    switch (GameLayer::getGameLevel()) {
        case EASY:
            minDuration = 3;
            maxDuration = 8;
            break;
        case NORMAL:
            minDuration = 1;
            maxDuration = 3;
            break;
        case HARD:
            minDuration = 0.5;
            maxDuration = 1;
            break;
            
        default:
            break;
    }
    int rangeDuration = maxDuration - minDuration;
    int aclDuration = (rand()%rangeDuration) + minDuration;
    CCFiniteTimeAction* moveTo = CCMoveTo::create(aclDuration, ccp(aclX, -2*enemy1Size.height));
    CCFiniteTimeAction* moveDone = CCCallFuncN::create(this, callfuncN_selector(EnemyLayer::enemyMoveFinish));
    CCSequence* sequence = CCSequence::create(moveTo,moveDone);
    enemy1->runAction(sequence);
    
}
开发者ID:hbflyhbfly,项目名称:AirPlane,代码行数:60,代码来源:EnemyLayer.cpp

示例8: addSubFormWithSpriteFrameNameAndKey

void RCUnit::addSubFormWithSpriteFrameNameAndKey(const char *frameName, AnimationParam *animationParam, const char *key)
{
    //add sprite
    if (!animationParam) {
        return;
    }

    CCAnimation *animation = CCAnimationCache::sharedAnimationCache()->animationByName(key);
    if (animation == NULL) {
        animation = CCAnimation::create();

        for (int i=1; i <= animationParam->count; i++) {
            CCString *realFrameName = CCString::createWithFormat("%s%.02i.png",animationParam->frameName.c_str(),i);
            CCSpriteFrame *frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(realFrameName->getCString());
            animation->addSpriteFrame(frame);
        }
        animation->setDelayPerUnit(animationParam->interval);
        animation->setLoops(animationParam->loops);
        animation->setRestoreOriginalFrame(animationParam->restoreFirstFrame);

        CCAnimationCache::sharedAnimationCache()->addAnimation(animation, key);
    }

    m_dictionary->setObject(animation, key);
}
开发者ID:ryanflees,项目名称:CocosAI,代码行数:25,代码来源:RCUnit.cpp

示例9:

PlaneLayer::PlaneLayer()
{
	Layer::init();

	CCSize winSize = CCDirector::sharedDirector()->getWinSize();

	auto spriteFrameCache = cocos2d::SpriteFrameCache::sharedSpriteFrameCache(); 
	spriteFrameCache->addSpriteFramesWithFile("shoot.plist");

	auto plane = Sprite::createWithSpriteFrame(spriteFrameCache->spriteFrameByName("hero1.png"));
	plane->setPosition(ccp(winSize.width/2, plane->getContentSize().height/2));
	addChild(plane,1,PlaneSpriteTag);

	Blink* blink = Blink::create(1,3);

	CCAnimation* animation = CCAnimation::create();
	animation->setDelayPerUnit(0.1);
	animation->addSpriteFrame(spriteFrameCache->spriteFrameByName("hero1.png"));
	animation->addSpriteFrame(spriteFrameCache->spriteFrameByName("hero2.png"));

	CCAnimate* animate = CCAnimate::create(animation);

	plane->runAction(blink);
	plane->runAction(CCRepeatForever::create(animate));
}
开发者ID:gexchai,项目名称:MyAirplane,代码行数:25,代码来源:PlaneLayer.cpp

示例10: botisGangLied

void ASBot::botisGangLied(){
    
    CCSprite* ani = CCSprite::createWithSpriteFrameName("Miku_GL_0.png");
    ani->setRotation(-90);
    ani->setScale(2);
    ani->setPosition(ccp(size.width*5/40,size.height*80.3/90+winDif*2*alpha*alpha));
    player1->addChild(ani,100);
    
    CCAnimation* pAnimation = CCAnimation::create();
    for (int i = 0 ; i < 16; i++) {
        string texName = "Miku_GL_" + int2string(i) + ".png";
        CCSpriteFrame* frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(texName.c_str());
        pAnimation->addSpriteFrame(frame);
    }
    pAnimation->setDelayPerUnit(0.1);
    pAnimation->setRestoreOriginalFrame(true);
    pAnimation->setLoops(1);
    
    CCAnimate* pAnimate = CCAnimate::create(pAnimation);
    CCActionInterval* attack = CCMoveBy::create(1.8, ccp(size.width*30/40,0));
    CCActionInterval* effect = CCSpawn::create(pAnimate,attack,NULL);
    CCCallFunc* remove = CCCallFuncN::create(player1, callfuncN_selector(ASGame::removeSprite));
    CCCallFunc* add = CCCallFuncN::create(this, callfuncN_selector(ASBot::botMinusHpByGangLie));
    CCSequence* seq = CCSequence::create(effect,remove,add,NULL);
    
    ani->runAction(seq);
}
开发者ID:nooboracle,项目名称:ForTest,代码行数:27,代码来源:ASBotGangLie.cpp

示例11: loadPlistForAnimationWithName

CCAnimation* GameObject::loadPlistForAnimationWithName(CCString* animationName, CCString* className){
    
    CCAnimation *animationToReturn = CCAnimation::create();
    CCSpriteFrame *frame;
    CCString *frameName;
    
    CCDictionary *plist = CCDictionary::createWithContentsOfFile(CCString::createWithFormat("%s.plist",className->getCString())->getCString());
    CCDictionary *anim = (CCDictionary*)plist->objectForKey(animationName->getCString());
    CCString *fileNamePrefix = (CCString*)anim->objectForKey("fileNamePrefix");
    CCString *delay = (CCString*)anim->objectForKey("delay");
    CCString *animationFrames = (CCString*)anim->objectForKey("animationFrames");
    
    std::vector<int> vect;
    
    std::stringstream ss(animationFrames->getCString());
    int i;
    
    while (ss >> i)
    {
        vect.push_back(i);
         
        if (ss.peek() == ',')
            ss.ignore();
    }

    for (vector<int>::size_type i = 1; i <= vect.size(); ++i)
    {
        frameName = CCString::createWithFormat("%s%i.png",fileNamePrefix->getCString(),i);
        frame= CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(frameName->getCString());
        animationToReturn->addSpriteFrame(frame);
    }
    animationToReturn->setDelayPerUnit(delay->floatValue());
    return animationToReturn;
}
开发者ID:abhi6699,项目名称:mvcsample,代码行数:34,代码来源:GameObject.cpp

示例12: init

//! 在此层中管理enemy的运动 爆炸 移除 和添加
bool LayerEnemy::init() 			
{ 						
	CCLayer::init(); 			

	m_psmallArray = CCArray::create();
	CC_SAFE_RETAIN(m_psmallArray);
	m_psmallArray->retain();
	m_psmallArray->autorelease();

	//! 缓存爆炸动画
	CCAnimation *smallAnimation = CCAnimation::create();
	smallAnimation->setDelayPerUnit(0.1f);
	char nameBuf[100];
	for (int i = 0; i < 4; i++)
	{
		memset(nameBuf, 0, sizeof(nameBuf));
		sprintf(nameBuf, "enemy1_down%d.png", i + 1);
		smallAnimation->addSpriteFrame
			(CCSpriteFrameCache::sharedSpriteFrameCache()
			->spriteFrameByName(nameBuf));
	}
	CCAnimationCache::sharedAnimationCache()->addAnimation(smallAnimation, "SmallBlowUp");

	schedule(schedule_selector(LayerEnemy::addSmallEnemy), 0.5f);

	return true;				
} 						
开发者ID:dalechngame,项目名称:mygame,代码行数:28,代码来源:LayerEnemy.cpp

示例13: SheldonPreAttackCritical

void ASFightLayer::SheldonPreAttackCritical(){
    //1.英雄身上闪光
    CCActionInterval* flash = CCTintBy::create(0.2, -3, -198, -213);
    CCDelayTime* delay = CCDelayTime::create(0.1);
    CCActionInterval* flash1 = CCTintBy::create(0.2, 3, 198, 213);
    CCSequence* seq = CCSequence::create(flash,delay,flash1,NULL);
    CCRepeatForever* effect = CCRepeatForever::create(seq);
    MainHero->runAction(effect);
    
    //2.蓄力动画
    blade = CCSprite::createWithSpriteFrameName("Sheldon_0_0.png");
    blade->setScaleY(2.5);
    blade->setScaleX(-2.5);
    blade->setPosition(ccp(size.width*50/50,winSize.height*45/70));
    addChild(blade,3);
    
    CCAnimation* pAnimation = CCAnimation::create();
    for (int i = 0 ; i < 17; i++) {
        string texName = "Sheldon_0_" + int2string(i) + ".png";
        CCSpriteFrame* frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(texName.c_str());
        pAnimation->addSpriteFrame(frame);
    }
    pAnimation->setDelayPerUnit(0.14);
    pAnimation->setRestoreOriginalFrame(true);
    pAnimation->setLoops(-1);
    CCAnimate* pAnimate = CCAnimate::create(pAnimation);
    
    blade->runAction(pAnimate);
}
开发者ID:nooboracle,项目名称:ForTest,代码行数:29,代码来源:SheldonCritical.cpp

示例14: startProcess

void UICenterItem::startProcess()
{
	valid = false;
	// 创建一个动画 自身播放时间到后将valid 设置为true
	CCAnimation* animation = CCAnimation::create();
		std::string frameNames[] = {
			std::string("skill_p_00000.png"),
			std::string("skill_p_00001.png"),
			std::string("skill_p_00002.png"),
			std::string("skill_p_00003.png"),
			std::string("skill_p_00004.png"),
			std::string("skill_p_00005.png"),
		};
	for (int i = 0; i < 3; i++)
	{
		CCTexture2D *texture = CCTextureCache::sharedTextureCache()->addImage(frameNames[i].c_str());
		
		CCSpriteFrame *frame = CCSpriteFrame::frameWithTexture(texture,CCRectMake(0,0,texture->getContentSize().width,texture->getContentSize().height));
		
		animation->addSpriteFrame(frame);
	}
	CCSprite * temp = CCSprite::create();
	this->getParent()->addChild(temp);
	temp->setPosition(this->getPosition());
	animation->setDelayPerUnit(1.5f / 2);
	animation->setRestoreOriginalFrame(true);
	temp->runAction(CCSequence::create(CCAnimate::create(animation),
		CCCallFuncND::create(this, callfuncND_selector(UICenterItem::actionEnd_setValid), (void*)temp),NULL));

}
开发者ID:coderHsc,项目名称:sygame,代码行数:30,代码来源:UICenterBag.cpp

示例15: createBird

void GameScene::createBird() {
    birdID = CCRANDOM_0_1() * 3;
    
    CCString* bName = CCString::createWithFormat("bird%d_0.png", birdID);
    CCSprite* bird = CCSprite::createWithSpriteFrameName(bName->getCString());
    bird->setPosition(ccp(screenSize.width * 0.25f, screenSize.height * 0.5f));
    addChild(bird, 4, TAG_BIRD);
    
    CCAnimation* animation = CCAnimation::create();
    for (int i = 0; i < 3; i++) {
        CCString* birdName = CCString::createWithFormat("bird%d_%d.png", birdID, i);
        CCSpriteFrame* frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(birdName->getCString());
        animation->addSpriteFrame(frame);
    }
    animation->setDelayPerUnit(0.08f);
    CCAnimate* animate = CCAnimate::create(animation);
    CCRepeat* br = CCRepeat::create(animate, 2);
    
    CCMoveBy* moveUp = CCMoveBy::create(0.5f, ccp(0, -bird->getContentSize().height * 0.4f));
    CCMoveBy* moveDown = CCMoveBy::create(0.5f, ccp(0, bird->getContentSize().height * 0.4f));
    CCSequence* moveSeq = CCSequence::create(moveUp, moveDown, NULL);
    
    CCSpawn* spawn = CCSpawn::create(br, moveSeq, NULL);
    
    CCRepeatForever* repeat = CCRepeatForever::create(spawn);
    bird->runAction(repeat);
}
开发者ID:eclipsezym,项目名称:Cocos2d-x_studying,代码行数:27,代码来源:GameScene.cpp


注:本文中的CCAnimation::addSpriteFrame方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。