void CSmeltArmor::initFire() { //获取参考位置 CCNode* pNode = (CCNode*)m_ui->findWidgetById("fire_circle"); CCPoint pPos = ccp(pNode->getPositionX()+15, pNode->getPositionY()+75); if(m_pFire1 == nullptr) { CCAnimation* pAnimation = AnimationManager::sharedAction()->getAnimation("9010"); pAnimation->setDelayPerUnit(0.15f); m_pFire1 = CCSprite::create("skill/9010.png"); m_pFire1->setPosition(pPos); m_pFire1->runAction(CCRepeatForever::create(CCAnimate::create(pAnimation))); m_pFire1->setVisible(false); m_pFire1->setScale(1.6f); pNode->getParent()->addChild(m_pFire1, pNode->getZOrder()); } if(m_pFire2 == nullptr) { CCAnimation* pAnimation = AnimationManager::sharedAction()->getAnimation("9011"); pAnimation->setDelayPerUnit(0.15f); m_pFire2 = CCSprite::create("skill/9011.png"); m_pFire2->setPosition(pPos); m_pFire2->runAction(CCRepeatForever::create(CCAnimate::create(pAnimation))); m_pFire2->setVisible(false); m_pFire2->setScale(1.5f); pNode->getParent()->addChild(m_pFire2, pNode->getZOrder()); } }
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 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 CTopLayer::onEnter() { BaseLayer::onEnter(); this->setTouchPriority(-100); UserData *user = DataCenter::sharedData()->getUser()->getUserData(); m_coinLabel = (CLabel*)m_ui->getChildByTag(13); m_coinLabel->setString(ToString(user->getCoin())); m_moneyLabel = (CLabel*)m_ui->getChildByTag(14); m_moneyLabel->setString(ToString(user->getRoleGold())); // m_foodLabel = (CLabel*)m_ui->getChildByTag(17); //m_foodLabel->setString(ToString(user->getRoleFood())); m_foodLabel->setString(ToString(user->getFriends())); CLabel *action = (CLabel*)(m_ui->findWidgetById("action")); action->setString(CCString::createWithFormat("%d/%d",user->getRoleAction(),user->getActionLimit())->getCString()); CButton* add_food = (CButton*)m_ui->findWidgetById("btn_add_food"); CButton* add_copper = (CButton*)m_ui->findWidgetById("btn_add_copper"); CButton* add_soul = (CButton*)m_ui->findWidgetById("btn_add_soul"); CButton* add_gold = (CButton*)m_ui->findWidgetById("btn_add_gold"); CButton* add_friendship = (CButton*)m_ui->findWidgetById("btn_add_friendship"); add_food->getSelectedImage()->setScale(1.1f); add_copper->getSelectedImage()->setScale(1.1f); add_soul->getSelectedImage()->setScale(1.1f); add_gold->getSelectedImage()->setScale(1.1f); add_friendship->getSelectedImage()->setScale(1.1f); add_food->setOnClickListener(this, ccw_click_selector(CTopLayer::onAddResourceBtn)); add_copper->setOnClickListener(this, ccw_click_selector(CTopLayer::onAddResourceBtn)); add_soul->setOnClickListener(this, ccw_click_selector(CTopLayer::onAddResourceBtn)); add_gold->setOnClickListener(this, ccw_click_selector(CTopLayer::onAddResourceBtn)); add_friendship->setOnClickListener(this, ccw_click_selector(CTopLayer::onAddResourceBtn)); CSceneManager::sharedSceneManager()->addMsgObserver(UPDATE_HERO,this,GameMsghandler_selector(CTopLayer::updateRoleProperty)); //绑定场景隐藏和显示的消息 NOTIFICATION->addObserver(this, callfuncO_selector(CTopLayer::show), SHOW_TOP_LAYER, nullptr); NOTIFICATION->addObserver(this, callfuncO_selector(CTopLayer::hide), HIDE_TOP_LAYER, nullptr); CImageView *coin = (CImageView*)(m_ui->findWidgetById("coin")); CCAnimation *coinAnim = AnimationManager::sharedAction()->getAnimation("7033"); coinAnim->setDelayPerUnit(0.3f); coin->runAction(CCRepeatForever::create(CCAnimate::create(coinAnim))); CImageView *gold = (CImageView*)(m_ui->findWidgetById("gold")); CCAnimation *goldAnim = AnimationManager::sharedAction()->getAnimation("7034"); goldAnim->setDelayPerUnit(0.3f); gold->runAction(CCRepeatForever::create(CCAnimate::create(goldAnim))); }
SpiritMain::SpiritMain(CCLayer* layer,MainRoledata roledata,int zOrder) { CCSprite* npc = SpiritMain::create(roledata.spiritUrl->getCString()); if(npc==NULL) { CCLog("图层路径有误,请检查路径"); return; } //设置NPC初始位置坐标(该坐标取决于当前画层) npc->setPosition(roledata.nowpoint); //NPC动画 CCAnimation* donghua = SpiritMain::getNowAnt(roledata); if(roledata.actiontime>0) { donghua->setDelayPerUnit(roledata.actiontime/roledata.maxcut_zhan); } else { donghua->setDelayPerUnit(2.0f/15.0f);//执行默认时间 } donghua->setRestoreOriginalFrame(true); donghua->setLoops(-1); CCAnimate* playdonghua = CCAnimate::create(donghua); npc->runAction(playdonghua); layer->addChild(npc,zOrder); // p_ui = new PublicShowUI(); p_ui->setGameText(layer,roledata.spiritname,ccp(roledata.nowpoint.x,roledata.nowpoint.y+(int)(npc->getTexture()->getPixelsHigh()*0.3f)),12); //添加NPC人物脚下阴影 CCSprite* yinzi = CCSprite::create(p_yinzi); if(yinzi==NULL) { CCLog("图层路径有误,请检查路径"); return; } yinzi->setZOrder(0); yinzi->setPosition(ccp(roledata.nowpoint.x,roledata.nowpoint.y-(int)(npc->getTexture()->getPixelsHigh()*0.2f))); layer->addChild(yinzi); //添加NPC人物聊天背景 CCSprite* sp_liaotianbd = CCSprite::create(p_liaotianbd); //sp_liaotianbd->setContentSize(CCSize(200,200)); sp_liaotianbd->setZOrder(2); sp_liaotianbd->setPosition(ccp(roledata.nowpoint.x,roledata.nowpoint.y-(int)(npc->getTexture()->getPixelsHigh()*0.2f))); layer->addChild(sp_liaotianbd); }
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; }
//! 在此层中管理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; }
//----------------------------------------------------------------------------- //todo 预载入资源,实现StartScene后将其删除 void CGameScene::preloadResources() { CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("fishingjoy_resource.plist"); //以下代码创建了两个不同的动画帧序列,使用时获取动画可以这么做:CCAnimation* animation = CCAnimationCache::sharedAnimationCache()->animationByName(const char* name); int frameCount = STATIC_DATA_INT("fish_frame_count"); for (int type = k_Fish_Type_Red; type < k_Fish_Type_Count; type++) { //以下代码会创建animation失败 // CCAnimation* fishAnimation = CCAnimation::create(); // for (int i = 0; i < frameCount; i++) // { // fishAnimation->addSpriteFrameWithFileName( // CCString::createWithFormat(STATIC_DATA_STRING("fish_frame_name_format"), type, i)->getCString()); // } CCArray* spriteFramesArray = CCArray::createWithCapacity(frameCount); for (int i = 0; i < frameCount; i++) { CCString* fileName = CCString::createWithFormat(STATIC_DATA_STRING("fish_frame_name_format"), type, i); CCSpriteFrame* spriteFrame = CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(fileName->getCString()); spriteFramesArray->addObject(spriteFrame); } CCAnimation* fishAnimation = CCAnimation::createWithSpriteFrames(spriteFramesArray); fishAnimation->setDelayPerUnit(STATIC_DATA_FLOAT("fish_frame_delay")); CCString* animationName = CCString::createWithFormat(STATIC_DATA_STRING("fish_animation"),type); CCAnimationCache::sharedAnimationCache()->addAnimation(fishAnimation, animationName->getCString()); } }
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)); }
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); }
bool PlaneLayer::init() { bool bRet = false; do { CC_BREAK_IF(!CCLayer::init()); CCSize winSize = CCDirector::sharedDirector()->getWinSize(); //CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("ui/shoot.plist"); CCSprite* plane = CCSprite::createWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("hero1.png")); plane->setPosition(ccp(winSize.width/2,plane->getContentSize().height/2)); this->addChild(plane,0,AIRPLANE); CCBlink* blink = CCBlink::create(1,3); CCAnimation* animation = CCAnimation::create(); animation->setDelayPerUnit(0.1f); animation->addSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("hero1.png")); animation->addSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("hero2.png")); CCAnimate* animate = CCAnimate::create(animation); plane->runAction(blink); plane->runAction(CCRepeatForever::create(animate)); bRet = true; } while (0); return bRet; }
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 CSharpTollgate::onEnter() { BaseLayer::onEnter(); CButton* pClose = CButton::create("common/back.png", "common/back.png"); pClose->getSelectedImage()->setScale(1.1f); pClose->setPosition(VLEFT+50, VTOP-50); pClose->setOnClickListener(this,ccw_click_selector(CSharpTollgate::onClose)); this->addChild(pClose, 999); m_cell = (CLayout*)(m_ui->findWidgetById("Cell")); // m_cell->retain(); // m_ui->removeChild(m_cell); CCAnimation *bgAnim = AnimationManager::sharedAction()->getAnimation("8055"); bgAnim->setDelayPerUnit(0.05f); CCSprite *bg = createAnimationSprite("skill/8055.png",VCENTER,bgAnim,true); bg->setScale(3.0f); m_ui->addChild(bg); m_tableView = (CTableView *)(m_ui->findWidgetById("scroll")); m_tableView->setDirection(eScrollViewDirectionHorizontal); m_tableView->setSizeOfCell(m_cell->getContentSize()); //m_tableView->setSizeOfCell(CCSizeMake(790,115)); m_tableView->setCountOfCell(0); m_tableView->setBounceable(false); m_tableView->setDataSourceAdapter(this,ccw_datasource_adapter_selector(CSharpTollgate::tableviewDataSource)); m_tableView->reloadData(); }
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); } }
void HelloWorld::GenerateHulkAnimation(char *Name,int Max,cocos2d::CCSprite* sp) { char *frameName = new char[1024]; cocos2d::CCAnimate *_curAnimate; CCAnimation* animaiton = CCAnimation::create(); for(int i = 1; i <= Max; ++i){ sprintf(frameName, "%s%d.png", Name, i); animaiton->addSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(frameName)); } for(int i = 1; i <= Max; ++i){ animaiton->addSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(frameName)); } animaiton->setDelayPerUnit(0.1); _curAnimate = CCAnimate::create(animaiton); //CCActionInterval* action = CCAnimate::actionWithDuration(1); //CCRepeatForever* repeatAction = CCRepeatForever::actionWithAction(action); //sp->runAction(repeatAction); sp->runAction(_curAnimate); }
void HelloWorld::runNamasteAnimation(CCObject* pSender) { SimpleAudioEngine::sharedEngine()->playEffect("angrypunch.mp3"); //GenerateHulkAnimation("namaste_1_",4,hulk); cocos2d::CCAnimate *_curAnimate; CCAnimation* animaiton = CCAnimation::create(); for(int i = 1; i <= 4; ++i){ char *frameName = new char[1024]; sprintf(frameName, "%s%d.png", "namaste_1_", i); animaiton->addSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(frameName)); } for(int i = 1; i <= 8; ++i){ animaiton->addSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("namaste_1_4.png")); } animaiton->setDelayPerUnit(0.1); _curAnimate = CCAnimate::create(animaiton); // CCActionInterval* action = CCAnimate::actionWithDuration(1); //CCRepeatForever* repeatAction = CCRepeatForever::actionWithAction(action); //sp->runAction(repeatAction); hulk->runAction(_curAnimate); }
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 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 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 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); }
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 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); }
void LoadScene::onEnter() { CScene::onEnter(); CSVFile* file = (CSVFile*)FileUtils::sharedFileUtils()->loadCSVFile(CSV_ROOT("preloadRes.csv")); schedule(schedule_selector(LoadScene::loadResource)); //进度条 mProgress = (CProgressBar*)m_ui->findWidgetById("progress"); mProgress->setMaxValue(100); //僵尸跳 CCAnimation *pZombieEffect = AnimationManager::sharedAction()->getAnimation("9049"); pZombieEffect->setDelayPerUnit(0.05f); CCAnimate* pAnimate = CCAnimate::create(pZombieEffect); CCSprite* pZombieSprite = CCSprite::create(); pZombieSprite->setScale(0.9f); pZombieSprite->setAnchorPoint(ccp(0.5f, 0.0f)); pZombieSprite->setPositionY(mProgress->getPositionY()+5); m_ui->addChild(pZombieSprite); pZombieSprite->runAction(CCRepeatForever::create(pAnimate)); m_pZombieSprite = pZombieSprite; CCSprite* tBackround = (CCSprite*)m_ui->findWidgetById("bg"); tBackround->initWithFile("warScene/LoadImage/1.png"); //容错性处理 }
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 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(); }
bool GridNode::init() { bool bRet = false; do { CCNode::init(); this->setContentSize(CCSize(GRID_WIDTH, GRID_HEIGHT)); m_gridSprite = CCSprite::create(); m_gridSprite->setAnchorPoint(CCPoint(0.5, 0.5)); m_gridSprite->setPosition(CCPoint(GRID_WIDTH / 2, GRID_HEIGHT / 2)); this->addChild(m_gridSprite, 10); m_animSprite = CCSprite::create(); m_animSprite->setAnchorPoint(CCPoint(0.5, 0.5)); m_animSprite->setPosition(CCPoint(GRID_WIDTH / 2, GRID_HEIGHT / 2)); m_animSprite->setVisible(false); this->addChild(m_animSprite, 0); CCAnimation* selectAnimatoin = CCAnimation::create(); CCString* frame; for (int i = 0; i < 5; i++) { frame = CCString::createWithFormat("select_frame_%d.png", i); selectAnimatoin->addSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName(frame->getCString())); } selectAnimatoin->setDelayPerUnit(0.5f / 5.0f); selectAnimatoin->setLoops(true); m_selectAnimate = CCRepeatForever::create(CCAnimate::create(selectAnimatoin)); m_selectAnimate->setTag(SELECT_ACTION_TAG); m_selectAnimate->retain(); 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 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()); }
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; }