void Mole::displayHurt() { this->unscheduleAllSelectors(); if(!isAction) { CCSpriteFrame *frame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("mole_11.png"); m_mole->setDisplayFrame(frame); CCSpriteFrameCache *frameCache = CCSpriteFrameCache::sharedSpriteFrameCache(); frameCache->addSpriteFramesWithFile("wakuang/mole_hurt.plist"); CCSpriteFrame* frame1 = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("20543.png"); CCSpriteFrame* frame2 = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("20544.png"); CCSpriteFrame* frame3 = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("20545.png"); CCArray* animFrames = CCArray::createWithCapacity(3); animFrames->addObject(frame1); animFrames->addObject(frame2); animFrames->addObject(frame3); CCAnimation *animation = CCAnimation::createWithSpriteFrames(animFrames, 0.15f); animation->setRestoreOriginalFrame(true); animFrames->removeAllObjects(); m_spade->runAction(CCAnimate::create(animation)); CCSpriteFrame* frame4 = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("20546.png"); CCSpriteFrame* frame5 = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("20547.png"); CCSpriteFrame* frame6 = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("20548.png"); animFrames->addObject(frame4); animFrames->addObject(frame5); animFrames->addObject(frame6); animation = CCAnimation::createWithSpriteFrames(animFrames, 0.15f); animation->setRestoreOriginalFrame(true); animFrames->removeAllObjects(); CCCallFunc* call = CCCallFunc::create(this,callfunc_selector(Mole::hurtActionOver)); m_hurt->runAction(CCSequence::create(CCAnimate::create(animation),call,NULL)); isAction = true; sendEvent(type); } }
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(); }
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(); }
void HistoryScr::defineAnimations() { //Engine animation CCArray *engineAnimFrames = CCArray::create(); for (int i = 1; i <= 3; i++) { CCString* framename = CCString::createWithFormat("engine%d.png", i); engineAnimFrames->addObject( CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName( framename->getCString())); } CCAnimation *engineAnim = CCAnimation::createWithSpriteFrames( engineAnimFrames, 0.09f); engineAnim->setRestoreOriginalFrame(true); CCAction *engineActionAnim = CCRepeatForever::create( CCAnimate::create(engineAnim)); engine->runAction(engineActionAnim); //Window Warning Animation }
//攻击动画 void Monster::AttackAnimation(const char *name_each,const unsigned int num,bool run_directon) { //正在走动、攻击、受伤或已死亡,就返回 if(IsRunning||IsAttack||IsHurt||Isdead) return; CCAnimation* animation = CCAnimation::create(); for( int i=1;i<=num;i++) { char szName[100] = {0}; sprintf(szName,"%s%d.png",name_each,i); animation->addSpriteFrameWithFileName(szName); //加载动画的帧 } animation->setDelayPerUnit(0.1f); animation->setRestoreOriginalFrame(true); animation->setLoops(1); //动画循环1次 //将动画包装成一个动作 CCAnimate* act=CCAnimate::create(animation); //创建回调动作,攻击结束后调用AttackEnd() CCCallFunc* callFunc=CCCallFunc::create(this,callfunc_selector(Monster::AttackEnd)); //创建连续动作 CCActionInterval* attackact=CCSequence::create(act,callFunc,NULL); m_MonsterSprite->runAction(attackact); IsAttack=true; }
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); }
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)); }
float Snake::moveBack() { //CCSprite::initWithFile("snakeBack1.png"); //pLife->setRotationY(180); deleteExploreShit(); this->stopAllActions(); CCAnimation* animation =CCAnimation::create(); char str[20]; for(int i=0;i<3;i++) { sprintf(str,"snakeBack%d.png",i + 1); animation->addSpriteFrameWithFileName(str); } animation->setDelayPerUnit(0.2f); animation->setRestoreOriginalFrame(true); myAction = CCRepeatForever::create(CCAnimate::create(animation)); this->runAction(myAction); CCSize size = CCDirector::sharedDirector()->getWinSize(); CCActionInterval *move = CCMoveTo::create(moveTime / 2,ccp(size.width, 12)); moveTo = CCSequence::create(move/*,CCCallFuncN::create(this,callfuncN_selector(GameLayer::deleteAnimal))*/,NULL); this->runAction(moveTo); hasMoveBack = true; return moveTime / 2; }
void ASFightLayer::SheldonSecondPeriodCritical(){ //1.击中特效 CCSprite* hitEffect = CCSprite::createWithSpriteFrameName("Sheldon_C2_0.png"); hitEffect->setScale(2); hitEffect->setPosition(ccp(size.width*2/3,winSize.height/2)); addChild(hitEffect,4); CCAnimation* pAnimation = CCAnimation::create(); for (int i = 0 ; i < 24; i++) { string texName = "Sheldon_C2_" + 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); CCCallFunc* remove = CCCallFuncN::create(this, callfuncN_selector(ASFightLayer::removeThis)); CCSequence* effect1 = CCSequence::create(pAnimate,remove,NULL); CCDelayTime* delay = CCDelayTime::create(1.5); CCCallFunc* hit = CCCallFuncN::create(this, callfuncN_selector(ASFightLayer::SheldonSecondHitEnemy)); CCSequence* effect2= CCSequence::create(delay,hit,NULL); CCActionInterval* effect3 = CCSpawn::create(effect1,effect2,NULL); hitEffect->runAction(effect3); }
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); }
bool Mole::init() { CCNode::init(); CCSpriteFrameCache *frameCache = CCSpriteFrameCache::sharedSpriteFrameCache(); frameCache->addSpriteFramesWithFile("wakuang/mole.plist"); CCArray* animFrames = CCArray::createWithCapacity(3); char str[128] = {0}; CCSpriteFrame *frame1 = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("mole_01.png"); CCSpriteFrame *frame2 = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("mole_02.png"); CCSpriteFrame *frame3 = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(this->getSpriteFramesName().c_str()); animFrames->addObject(frame1); animFrames->addObject(frame2); animFrames->addObject(frame3); CCAnimation *animation = CCAnimation::createWithSpriteFrames(animFrames, 0.15f); animation->setRestoreOriginalFrame(true); animFrames->removeAllObjects(); m_mole = CCSprite::create(); m_mole->setDisplayFrame(frame3); CCCallFunc* call = CCCallFunc::create(this,callfunc_selector(Mole::displayActionOver)); m_mole->runAction(CCSequence::create(CCAnimate::create(animation),call,NULL)); this->addChild(m_mole); m_spade = CCSprite::create(); this->addChild(m_spade); m_hurt=CCSprite::create(); this->addChild(m_hurt); return true; }
void GameObjHero::setState(short var){ if(state == var) return; state = var; switch(state){ case 1://跳跃 this->stopAllActions(); mainsprite->stopAllActions(); mainsprite->setTexture(jump); this->runAction(CCSequence::create(CCJumpBy::create(2.5,Point(0,0),100,1),CCCallFunc::create(this, callfunc_selector(GameObjHero::jumpend)),NULL)); break; case 2://受伤 this->stopAllActions(); mainsprite->stopAllActions(); mainsprite->setTexture(hurt); this->runAction(CCSequence::create(CCBlink::create(3, 10),CCCallFunc::create(this, callfunc_selector(GameObjHero::hurtend)),NULL)); ((GameMain *)this->getParent())->setover(); break; case 0://奔跑动画 this->stopAllActions(); mainsprite->stopAllActions(); CCAnimation * animation = CCAnimation::create(); animation->addSpriteFrameWithFile("s_1.png"); animation->addSpriteFrameWithFile("s_2.png"); animation->addSpriteFrameWithFile("s_3.png"); animation->addSpriteFrameWithFile("s_4.png"); animation->addSpriteFrameWithFile("s_5.png"); animation->addSpriteFrameWithFile("s_6.png"); animation->setDelayPerUnit(0.1f); animation->setRestoreOriginalFrame(true); mainsprite->runAction(CCRepeatForever::create(CCAnimate::create(animation))); break; } }
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); }
CCAnimate* SpiritsPlayer::updateNowAnt_change(MainRoledata roledata,int RepeatNum) { //NPC动画 CCAnimation* donghua = SpiritsPlayer::getNowAnt(roledata); if(roledata.actiontime>0) { donghua->setDelayPerUnit(roledata.actiontime/roledata.maxcut_zhan); } else { donghua->setDelayPerUnit(2.0f/15.0f);//执行默认时间 } donghua->setRestoreOriginalFrame(true); if(RepeatNum>0) { donghua->setLoops(RepeatNum); } else { donghua->setLoops(-1); } CCAnimate* playdonghua = CCAnimate::create(donghua); return playdonghua; }
void ASBotFightLayer::BladeMasterPreAttack(){ CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("bmattack.mp3", false); //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("Blade_0_0.png"); blade->setRotation(-90); blade->setScaleY(2); blade->setScaleX(-1.2); blade->setOpacity(100); blade->setPosition(ccp(size.width*21/50,winSize.height/2)); addChild(blade,3); CCAnimation* pAnimation = CCAnimation::create(); for (int i = 0 ; i < 6; i++) { string texName = "Blade_0_" + 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); blade->runAction(pAnimate); }
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); }
void RoleJoyPad::initAction() { //元素动作数组 m_actionArray = CCArray::createWithCapacity(5); m_actionArray->retain(); char fileName1[64] = {0}; char fileName2[64] = {0}; char fileName3[64] = {0}; for (int i = 1; i != 6; ++i) { sprintf(fileName1, "item_%d_3.png", i); sprintf(fileName2, "item_%d_4.png", i); sprintf(fileName3, "item_%d_5.png", i); CCSpriteFrame* frame1 = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(fileName1); CCSpriteFrame* frame2 = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(fileName2); CCSpriteFrame* frame3 = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(fileName3); //消除帧动画 CCAnimation* animation = CCAnimation::create(); animation->addSpriteFrame(frame1); animation->addSpriteFrame(frame2); animation->addSpriteFrame(frame3); animation->setDelayPerUnit(0.3f/3); animation->setRestoreOriginalFrame(false); CCAnimate* animate = CCAnimate::create(animation); CCSpawn* animate_action = CCSpawn::create(animate, CCMoveBy::create(0.15f, ccp(0, 30)), NULL); m_actionArray->addObject(animate_action); } }
bool Snake::init() { bool bRet = false; do { CC_BREAK_IF(!CCSprite::initWithFile("snake1.png")); pLife->setPosition(ccp(pLife->getContentSize().width / 2,this->getContentSize().height + pLife->getContentSize().height)); CCAnimation* animation =CCAnimation::create(); //char *spriteImg[] = {"snake1.png","snake2.png","snake3.png","snake4.png","snake5.png","snake6.png","snake7.png"}; char str[20]; for(int i=0;i<7;i++) { sprintf(str,"snake%d.png",i + 1); animation->addSpriteFrameWithFileName(str); } animation->setDelayPerUnit(0.1f); animation->setRestoreOriginalFrame(true); myAction = CCRepeatForever::create(CCAnimate::create(animation)); myAction->retain(); CCSize size = CCDirector::sharedDirector()->getWinSize(); this->setPosition(ccp(size.width, 12)); produceLoc = ccp(size.width, 12); bRet = true; } while (0); return bRet; }
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); }
//怪物走动的动画 void Monster::SetAnimation(const char *name_each,unsigned int num,bool run_directon) { //设置方向 if(MonsterDirecton!=run_directon) { MonsterDirecton=run_directon; m_MonsterSprite->setFlipX(run_directon); } //正在走动、攻击、受伤或已死亡,就返回 if(IsRunning||IsAttack||IsHurt||Isdead) return; //设置动画 CCAnimation* animation = CCAnimation::create(); for( int i=1;i<=num;i++) { char szName[100] = {0}; sprintf(szName,"%s%d.png",name_each,i); animation->addSpriteFrameWithFileName(szName); //加载动画的帧 } animation->setDelayPerUnit(0.1f);//每两张图片的时间间隔 animation->setRestoreOriginalFrame(true); animation->setLoops(-1); //动画循环 //将动画包装成一个动作 CCAnimate* act=CCAnimate::create(animation); m_MonsterSprite->runAction(act); IsRunning=true; }
void Game2Scene::eat(float dt) { CCSprite* player = (CCSprite*)this->getChildByTag(4); player->setTexture(CCTextureCache::sharedTextureCache()->addImage("monkey01.png")); //SEの再生 //SimpleAudioEngine::sharedEngine()->playEffect(SE); //アニメーション CCAnimation* ani = CCAnimation::create(); for (int i = 3; i <= 5; i++) { char szName[100] = { 0 }; sprintf(szName, "monkey%02d.png", i); ani->addSpriteFrameWithFileName(szName); } ani->setDelayPerUnit(0.15 / 3); ani->setRestoreOriginalFrame(true); ani->setLoops(2); CCAnimate* act = CCAnimate::create(ani); player->runAction(act); //スコアシステム作成 CCSize winSize = CCDirector::sharedDirector()->getWinSize(); CCLabelTTF* Label = (CCLabelTTF*)this->getChildByTag(22); this->m_Count += 1; CCString* gamePoints = CCString::createWithFormat("%d", this->m_Count); Label->setString(gamePoints->getCString()); }
CCAnimation* AnimationUtil::createAnimWithSingleFrameN( const char* name, float delay, unsigned int iLoops) { CCSpriteFrameCache* cache = CCSpriteFrameCache::sharedSpriteFrameCache(); CCArray* framesArray = CCArray::create(); CCSpriteFrame* frame = NULL; int index = 1; do { frame = cache->spriteFrameByName(CCString::createWithFormat("%s%d.png", name, index++)->getCString()); /* 不断地获取CCSpriteFrame对象,直到获取的值为NULL */ if(frame == NULL) { break; } framesArray->addObject(frame); }while(true); CCAnimation* animation = CCAnimation::createWithSpriteFrames(framesArray); animation->setLoops(iLoops); animation->setRestoreOriginalFrame(true); animation->setDelayPerUnit(delay); return animation; }
void *HistoryScr::generateFire(CCPoint position) { //generate sprite CCSprite *meteorFire = CCSprite::createWithSpriteFrameName("fire1.png"); //generate fire CCArray *fireAnimFrames = CCArray::create(); for (int i = 1; i <= 3; i++) { CCString* framename = CCString::createWithFormat("fire%d.png", i); fireAnimFrames->addObject( CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName( framename->getCString())); } CCAnimation *fireAnim = CCAnimation::createWithSpriteFrames(fireAnimFrames, 0.09f); fireAnim->setRestoreOriginalFrame(true); CCAction *fireActionAnim = CCRepeatForever::create( CCAnimate::create(fireAnim)); meteorFire->setScale(0.85); meteorFire->setPosition(position); ship->addChild(meteorFire); meteorFire->runAction(fireActionAnim); }
void ASFightLayer::IronManPreAttack(){ if(!MainUser->muted) CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("ironmanattack.mp3"); //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("IronMan_hit_0.png"); blade->setOpacity(100); blade->setPosition(ccp(size.width*19/50,winSize.height*9.8/20)); addChild(blade,3); CCAnimation* pAnimation = CCAnimation::create(); for (int i = 0 ; i < 4; i++) { string texName = "IronMan_hit_" + 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); blade->runAction(pAnimate); }
void ASBotFightLayer::SwordFall(){ sword = CCSprite::createWithSpriteFrameName("LichKing_C3_0.png"); sword->setScaleX(-7); sword->setScaleY(7); sword->setPosition(ccp(size.width*3/7, winSize.height*6/7)); addChild(sword,2); CCAnimation* pAnimation = CCAnimation::create(); for (int i = 0 ; i < 24; i++) { string texName = "LichKing_C3_" + 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); CCDelayTime* delay = CCDelayTime::create(2); CCActionInterval* moveDown = CCMoveBy::create(0.5, ccp(0, -winSize.height*11/20)); CCSequence* effect1 = CCSequence::create(delay,moveDown,NULL); CCDelayTime* delay1 = CCDelayTime::create(2.3); CCCallFunc* hit = CCCallFuncN::create(this, callfuncN_selector(ASBotFightLayer::LichKingBigAttack)); CCSequence* effect2 = CCSequence::create(delay1,hit,NULL); CCActionInterval* effect3 = CCSpawn::create(pAnimate,effect1,effect2,NULL); sword->runAction(effect3); }
} CCAction* HelloWorld::createAction(int begin,int end,char* cacheActionName,CCPoint point){ CCAnimationCache *animCache = CCAnimationCache::sharedAnimationCache(); CCArray *array = CCArray::createWithCapacity(end-begin); char name[20]; for(int i = begin ;i<end;i++){ sprintf(name,"A1_%d.png",i); CCSpriteFrame* frame =cache->spriteFrameByName(name); array->addObject(frame); } CCAnimation *plistAnimation = CCAnimation::createWithSpriteFrames(array,0.2f); CCAnimationCache::sharedAnimationCache()->addAnimation(plistAnimation, cacheActionName); array->removeAllObjects(); CCAnimation *animation = animCache->animationByName(cacheActionName); animation->setRestoreOriginalFrame(true); CCAnimate *ani=CCAnimate::create(animation); CCActionInterval* plistSeq=(CCActionInterval*)(CCSequence::create(ani, CCFlipX::create(point.x>0? true:false), ani->copy()->autorelease(), NULL ));
void GameObjHero::onEnter() { CCNode::onEnter(); this->setContentSize(CCSizeMake(85, 90)); CCDirector *pDirector = CCDirector::sharedDirector(); pDirector->getTouchDispatcher()->addTargetedDelegate(this, 0, true); CCSprite *obj = CCSprite::create("s_hurt.png"); hurt = obj->getTexture(); obj = CCSprite::create("s_jump.png"); jump = obj->getTexture(); mainsprite = CCSprite::create("s_1.png"); //动画 CCAnimation *animation = CCAnimation::create(); animation->addSpriteFrameWithFileName("s_1.png"); animation->addSpriteFrameWithFileName("s_2.png"); animation->addSpriteFrameWithFileName("s_3.png"); animation->addSpriteFrameWithFileName("s_4.png"); animation->addSpriteFrameWithFileName("s_5.png"); animation->addSpriteFrameWithFileName("s_6.png"); animation->setDelayPerUnit(0.1f); animation->setRestoreOriginalFrame(true); //运行奔跑动画 mainsprite->runAction(CCRepeatForever::create(CCAnimate::create(animation))); state = 0; addChild(mainsprite); }
void Fish::spawnOneFish(Fish *fish) { assert(NULL != fish); fish->fish_sprite->stopAllActions(); fish->fish_sprite->setVisible(true); /** 游动 */ CCArray *fish_frames = CCArray::create(); for(int i = 1; i <= FISH_FRAMES_NUMBER; i++) { CCString *frame_name = CCString::createWithFormat("fish%02d_%02d.png", fish->fish_id, i); CCSpriteFrame *pFrame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(frame_name->getCString()); if(pFrame) { fish_frames->addObject(pFrame); } } CCAnimation *animation = CCAnimation::createWithSpriteFrames(fish_frames, 0.2f); animation->setRestoreOriginalFrame(false); CCAnimate *animate = CCAnimate::create(animation); CCAction *swing = CCRepeatForever::create(animate); fish->fish_sprite->runAction(swing); /** 路径 */ int index = rand() % PATH_CONF_TOTAL; // debug path //index = 16; CCPoint start_pos = g_path_config[index].start_pos; CCPoint control_pos = g_path_config[index].control_pos; CCPoint end_pos = g_path_config[index].end_pos; float start_angle = g_path_config[index].start_angle - SPRITE_OFFSET; float end_angle = g_path_config[index].end_angle - SPRITE_OFFSET; float time = fish_conf[fish->group_id].speed + rand() % 10; int x_offset = rand() % 100 -50; int y_offset = rand() % 100 -50; CCPoint s_pos = ccp(start_pos.x + x_offset, start_pos.y + y_offset); CCPoint e_pos = ccp(end_pos.x + rand() % 50 - 25, end_pos.y + rand() % 50 - 25); CCPoint c_pos = ccp(control_pos.x + x_offset, control_pos.y + y_offset); fish->fish_sprite->setPosition(s_pos); fish->fish_sprite->setRotation(start_angle); ccBezierConfig bezier; bezier.controlPoint_1 = s_pos; bezier.controlPoint_2 = c_pos; bezier.endPosition = e_pos; CCBezierTo *actionMove = CCBezierTo::create(time, bezier); CCRotateTo *actionRotate = CCRotateTo::create(time, end_angle); CCActionInterval *action = CCSpawn::create(actionMove, actionRotate, NULL); /** 完成预订动作将自己设置为不可见 */ CCFiniteTimeAction *callFunc = CCCallFuncN::create(fish, callfuncN_selector(Fish::hideSelf)); CCSequence *actionSequence = CCSequence::create(action, callFunc, NULL); fish->fish_sprite->runAction(actionSequence); }
void ASBotFightLayer::LichKingHitEnemy(){ //1.移除技能粒子的飞行特效 removeChild(skillEffect_fly); removeChild(blade); //2.击中特效 CCSprite* hitEffect = CCSprite::createWithSpriteFrameName("LichKing_hit_0.png"); hitEffect->setScale(-3); hitEffect->setOpacity(200); hitEffect->setPosition(ccp(size.width*20/50,winSize.height/2)); addChild(hitEffect,4); CCAnimation* pAnimation = CCAnimation::create(); for (int i = 0 ; i < 10; i++) { string texName = "LichKing_hit_" + 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); CCCallFunc* remove = CCCallFuncN::create(this, callfuncN_selector(ASBotFightLayer::removeThis)); CCSequence* seqqq = CCSequence::create(pAnimate,remove,NULL); hitEffect->runAction(seqqq); //3.英雄被击中后的动作 CCActionInterval* shake1 = CCRotateTo::create(0.15, 30); CCActionInterval* shake2 = CCRotateTo::create(0.15, 0); CCActionInterval* shake3 = CCRotateTo::create(0.15, -30); CCActionInterval* shake4 = CCRotateTo::create(0.15, 0); CCSequence* seq = CCSequence::create(shake1,shake2,shake3,shake4,NULL); BotHero->runAction(seq); //4.减血提示 string damageStr = "-" + int2string(damage) + "\n" + "答错遭受额外伤害!"; minusHP = CCLabelTTF::create(damageStr.c_str(), "Arial", 62.5); minusHP->setPosition(ccp(size.width*22/70, winSize.height*5.5/7)); minusHP->setRotation(-20); addChild(minusHP,5); CCActionInterval* scaleDown = CCScaleTo::create(0.3,1); CCActionInterval* fadeOut = CCFadeOut::create(2); CCCallFunc* back = CCCallFuncN::create(this, callfuncN_selector(ASBotFightLayer::backToMainGame)); CCSequence* seq1 = CCSequence::create(scaleDown,fadeOut,back,NULL); minusHP->runAction(seq1); CCActionInterval* flash = CCTintBy::create(0.2, -255, -91, -220); CCDelayTime* delay = CCDelayTime::create(0.1); CCActionInterval* flash1 = CCTintBy::create(0.2, 255, 91, 220); CCSequence* seq321 = CCSequence::create(flash,delay,flash1,NULL); CCRepeatForever* effect = CCRepeatForever::create(seq321); BotHero->runAction(effect); }
void Player::InitAnimation() { CCSpriteFrameCache* cache = CCSpriteFrameCache::sharedSpriteFrameCache(); CCAnimation* runAnim = CCAnimation::create(); char str[64] = {0}; //Right. { runAnim = CCAnimation::create(); for (int i = 0; i <= 2; i++) { sprintf(str, "move_right%d.png", i); CCSpriteFrame* frame = cache->spriteFrameByName(str); runAnim->addSpriteFrame(frame); } runAnim->setDelayPerUnit(0.04f); runAnim->setRestoreOriginalFrame(true); walk_Right_Animate = CCRepeatForever::create(CCAnimate::create(runAnim)); walk_Right_Animate->retain(); } //Up. { runAnim = CCAnimation::create(); for (int i = 0; i <= 1; i++) { sprintf(str, "move_up%d.png", i); CCSpriteFrame* frame = cache->spriteFrameByName(str); runAnim->addSpriteFrame(frame); } runAnim->setDelayPerUnit(0.04f); runAnim->setRestoreOriginalFrame(true); flip_Animate = CCRepeatForever::create(CCAnimate::create(runAnim)); flip_Animate->retain(); } }