Animate* Coin::createAnimate(SpriteFrameCache* frameCache){ SpriteFrame* frame = NULL; //数组不行 要用vector //auto frameArray = Array::create(); //frameArray->retain(); Vector<SpriteFrame*>frameArray; // 用一个列表保存所有SpriteFrame对象 for(int i = 0; i <= 7; i++) { /* 从SpriteFrame缓存池中获取CCSpriteFrame对象 */ frame = frameCache->spriteFrameByName(String::createWithFormat("coin%d.png", i)->getCString()); frameArray.pushBack(frame); } /* 使用SpriteFrame列表创建动画对象 */ auto animation = Animation::createWithSpriteFrames(frameArray); animation->setLoops(-1); animation->setDelayPerUnit(0.1f); /* 将动画包装成一个动作 */ auto action = Animate::create(animation); return action; }
void Monster_UI::runCuttleBoomAction() { auto sprite_boom = Sprite::create(); sprite->addChild(sprite_boom); auto ani = Animation::create(); ani->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("PCuttle01.png")); ani->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("PCuttle02.png")); ani->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("PCuttle03.png")); ani->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("PCuttle04.png")); ani->setDelayPerUnit(0.05); ani->setRestoreOriginalFrame(false); ani->setLoops(-1); sprite_boom->runAction(Animate::create(ani)); sprite_boom->setVisible(true); sprite_boom->setPosition(sprite->getContentSize().width / 2, sprite->getContentSize().height / 2); sprite_boom->runAction(Sequence::create(DelayTime::create(0.2), CallFunc::create([=]() { sprite_boom->removeFromParentAndCleanup(true); }), nullptr)); }
void FMCSound::play() { m_has_played = true; setLoops(m_play_looped ? -1 : 1); QSound::play(); m_play_dt.start(); }
void Fly::deadAction() { //主机在死亡的时候会调用deadAction()方法 //先停止所有动作和定时器 stopAllActions(); unscheduleAllSelectors(); //制作主机死亡的动作 auto pAnimation = cocos2d::Animation::create(); auto pSpriteFrameCache = cocos2d::SpriteFrameCache::getInstance(); for (int i = 1; i <= FLY_BLOWUP_FRAME_COUNT; ++i) { pAnimation->addSpriteFrame(pSpriteFrameCache->getSpriteFrameByName(cocos2d::StringUtils::format("hero_blowup_%d.png", i))); } pAnimation->setDelayPerUnit(0.1f); pAnimation->setLoops(1); auto pAnimate = cocos2d::Animate::create(pAnimation); //制作主机死亡动作播放完成后的处理动作 auto pEnd = cocos2d::CallFunc::create([]() { SceneManager::getInstance()->changeScene(en_GameOverScene); CocosDenshion::SimpleAudioEngine::getInstance()->playBackgroundMusic(GAME_OVER); }); //将死亡动作和死亡处理动作串行处理 runAction(cocos2d::Sequence::create(pAnimate, pEnd, NULL)); }
Torus::Torus(GLfloat inner, GLfloat outer, GLint slices, GLint loops) { setInner(inner); setOuter(outer); setSlices(slices); setLoops(loops); }
Tower_Shit::Tower_Shit(Node*scene, Vec2 pos, int lev) { view_click = 0; count = 0; cos_upgrade = 220; this->level = lev; initTowerBase(); effect = 0; sprite = Sprite::createWithSpriteFrameName("Shit11.png"); sprite;; sprite_base = MenuItemSprite::create(Sprite::createWithSpriteFrameName("Shit-11.png"), Sprite::createWithSpriteFrameName("Shit-11.png") , [=](Ref*p) { if (view_click == 0) { ((Scene_UI*)scene)->view_click_gloal->setAllVisFalse(); view_click = new View_Click_Tower(2, this); } }); sprite_base->setPosition(pos); sprite_base;; auto ss = Menu::create(sprite_base, nullptr); ss->setPosition(0, 0); scene->addChild(ss); scene->addChild(sprite); sprite->setPosition(pos); sprite_upgrade = Sprite::createWithSpriteFrameName("showupgrade02.png"); scene->addChild(sprite_upgrade); sprite_upgrade->setPosition(sprite->getPositionX(), sprite->getPositionY() + sprite->getContentSize().height); auto ani2 = Animation::create(); ani2->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("showupgrade02.png")); ani2->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("showupgrade01.png")); ani2->setDelayPerUnit(0.1); ani2->setRestoreOriginalFrame(false); ani2->setLoops(-1); sprite_upgrade->runAction(Animate::create(ani2)); sprite_upgrade->setVisible(false); setLevel(lev); }
StandardModel<Two_scale>::StandardModel(const StandardModel<Two_scale>& s) : yu(s.yu), yd(s.yd), ye(s.ye), g(s.g) { setPars(numStandardModelPars); setMu(s.displayMu()); setLoops(s.displayLoops()); setThresholds(s.displayThresholds()); }
bool Player::init(int typeID) { runSpeed = 400; char pngName[260] = { 0 }; sprintf(pngName, "res/image/anim%d/stay1.png", typeID); _player = Sprite::create(pngName); _player->setAnchorPoint(Vec2(0.5, 0)); Vector<SpriteFrame*> frameVector; for (int i = 1; i <= 5; i++) { char pngName[260] = { 0 }; sprintf(pngName, "res/image/anim%d/stay%d.png", typeID, i); frameVector.pushBack(SpriteFrame::create(pngName, Rect(0, 0, 54, 58))); } auto StayAnimation = Animation::createWithSpriteFrames(frameVector, 0.1); StayAnimation->setRestoreOriginalFrame(false); StayAnimation->setLoops(-1); StayAnimate = Animate::create(StayAnimation); StayAnimate->retain(); //2 frameVector.clear(); for (int i = 1; i <= 5; i++) { char pngName[260] = { 0 }; sprintf(pngName, "res/image/anim%d/walk%d.png",typeID, i); frameVector.pushBack(SpriteFrame::create(pngName, Rect(0, 0, 54, 58))); } auto WalkAnimation = Animation::createWithSpriteFrames(frameVector, 1); WalkAnimation->setRestoreOriginalFrame(false); WalkAnimation->setLoops(-1); // WalkAnimation->setDelayPerUnit(1); WalkAnimate = Animate::create(WalkAnimation); /** * 在析构函数中进行释放,否则会被自动释放;导致空指针 */ WalkAnimate->retain(); return true; }
StandardModel<Two_scale>::StandardModel() : yu(3, 3), yd(3, 3), ye(3, 3), g(3) , precision(1.0e-3) { setPars(numStandardModelPars); setMu(0.0); setLoops(1); setThresholds(0); }
StandardModel<Two_scale>::StandardModel(const DoubleMatrix& SMu, const DoubleMatrix& SMd, const DoubleMatrix& SMe, const DoubleVector& g_) : yu(SMu), yd(SMd), ye(SMe), g(g_) { setPars(numStandardModelPars); setMu(0.0); setLoops(1); setThresholds(0); }
void Tower_Ball::Destory() { Scene_UI*sc = (Scene_UI*)sprite->getParent(); for (vector<Tower_UI*>::iterator it = sc->tower_queue.begin(); it != sc->tower_queue.end(); ++it) { if ((*it) == this) { sc->tower_queue.erase(it); break; } } setClick(false); setTarget(0); auto x = (Scene_UI*)sprite->getParent(); x->data->pop(PublicFunc::convertToX(sprite->getPosition().x), PublicFunc::convertToY(sprite->getPosition().y)); auto ani = Animation::create(); ani->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("air01.png")); ani->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("air02.png")); ani->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("air03.png")); ani->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("air04.png")); ani->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("air05.png")); ani->setDelayPerUnit(0.1); ani->setRestoreOriginalFrame(true); ani->setLoops(1); auto an = Animate::create(ani); sprite_base->removeFromParentAndCleanup(true); effect->removeFromParentAndCleanup(true); sprite_bullet_effect->removeFromParentAndCleanup(true); sprite_upgrade->removeFromParentAndCleanup(true); sprite->runAction(Sequence::create(an, CallFunc::create([=] { sprite->removeFromParentAndCleanup(true); delete this; }), nullptr)); }
void MssmSusy::setSusy(const MssmSusy & s) { setLoops(s.displayLoops()); setThresholds(s.displayThresholds()); setMu(s.displayMu()); setYukawaMatrix(YU, s.displayYukawaMatrix(YU)); setYukawaMatrix(YD, s.displayYukawaMatrix(YD)); setYukawaMatrix(YE, s.displayYukawaMatrix(YE)); setHvev(s.displayHvev()); setTanb(s.displayTanb()); setSusyMu(s.displaySusyMu()); setAllGauge(s.displayGauge()); }
void Monster_UI::set_effect_last_damage(int lev)/*pin 持续伤害*/ { if (effect_last_damage_lev == 0) { sprite_last_damage = Sprite::create(); sprite->addChild(sprite_last_damage); auto ani1 = Animation::create(); ani1->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("PPin01.png")); ani1->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("PPin02.png")); ani1->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("PPin03.png")); ani1->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("PPin04.png")); ani1->setDelayPerUnit(0.03); ani1->setRestoreOriginalFrame(false); ani1->setLoops(-1); sprite_last_damage->runAction(Animate::create(ani1)); sprite_last_damage->setPosition(sprite->getContentSize().width / 2, 20); effect_last_damage_times = 5; sprite_last_damage->runAction(RepeatForever::create(Sequence::create(DelayTime::create(0.5), CallFunc::create([=]() { if (effect_last_damage_times >= 0) { --effect_last_damage_times; sprite_last_damage->setVisible(true); beenAttacked(effect_last_damage_lev * 1); sprite_last_damage->setPosition(sprite->getContentSize().width / 2, 20); } else { sprite_last_damage->setVisible(false); } }), nullptr))); } if (effect_last_damage_lev <= lev) { /*等级比之前的大*/ effect_last_damage_lev = lev; effect_last_damage_times = 5; sprite_last_damage->setVisible(true); } sprite_last_damage->setPosition(sprite->getContentSize().width / 2, 20); }
const StandardModel<Two_scale>& StandardModel<Two_scale>::operator=(const StandardModel<Two_scale>& s) { if (this == &s) return *this; yu = s.yu; yd = s.yd; ye = s.ye; g = s.g; setMu(s.displayMu()); setLoops(s.displayLoops()); setThresholds(s.displayThresholds()); return *this; }
const QedQcd & QedQcd::operator=(const QedQcd & m) { if (this == &m) return *this; a = m.a; mf = m.mf; mbPole = m.mbPole; input = m.input; ckm = m.ckm; pmns = m.pmns; setLoops(m.displayLoops()); setThresholds(m.displayThresholds()); setMu(m.displayMu()); return *this; }
void AnimationManager::loadHeroAnimation(const char *plist) { auto cache = SpriteFrameCache::getInstance(); cache->addSpriteFramesWithFile(plist); auto animation = Animation::create(); for (int i = 1; i < 3; i++) { auto filename = StringUtils::format("mainplaneIdle%d.png", i); animation->addSpriteFrame(cache->getSpriteFrameByName(filename)); } animation->setDelayPerUnit(0.1f); animation->setLoops(-1); m_manager->addAnimation(animation, "hero-normal"); }
void Monster_fat_green::runMoveAction() { auto ani = Animation::create(); ani->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("fat_green01.png")); ani->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("fat_green02.png")); ani->setDelayPerUnit(3.0 / 30.0); ani->setRestoreOriginalFrame(false); ani->setLoops(-1); auto an = Animate::create(ani); sprite->runAction(an); }
void Monster_UI::set_effect_pause_fish(int lev)/*fish 暂停*/ { if (effect_pause_lev_1 == 0) { sprite_effect_pause_1 = Sprite::create(); sprite->addChild(sprite_effect_pause_1); effect_pause_times_1 = 6; sprite_effect_pause_1->setPosition(sprite->getContentSize().width / 2, 50); auto ani1 = Animation::create(); ani1->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("PFish-11.png")); ani1->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("PFish-12.png")); ani1->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("PFish-13.png")); ani1->setDelayPerUnit(0.1); ani1->setRestoreOriginalFrame(false); ani1->setLoops(-1); sprite_effect_pause_1->runAction(Animate::create(ani1)); sprite_effect_pause_1->runAction(RepeatForever::create(Sequence::create(DelayTime::create(0.12), CallFunc::create([=]() { if (effect_pause_times_1 >= 0) { --effect_pause_times_1; sprite->pause(); sprite_effect_pause_1->setVisible(true); } else { sprite_effect_pause_1->setVisible(false); sprite->resume(); } }), nullptr))); } if (effect_pause_lev_1 <= lev) { /*等级比之前的大*/ effect_pause_lev_1 = lev; effect_pause_times_1 = 6; sprite_effect_pause_1->setPosition(sprite->getContentSize().width / 2, 40); } }
Animate*Tower_Pin::getAttackAction() { string str = ""; switch (level) { case 1: { str = "Pin1"; }break; case 2: { str = "Pin2"; }break; case 3: { str = "Pin3"; }break; } auto ani = Animation::create(); //ani->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName(str + "1.png")); ani->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName(str + "2.png")); ani->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName(str + "3.png")); ani->setDelayPerUnit(0.05); ani->setRestoreOriginalFrame(true); ani->setLoops(1); auto an = Animate::create(ani); return an; }
void Mainplan::addAnimation() { //加载飞机动画。 auto anim = Animation::create(); SpriteFrame *sf; //通过桢缓存名字动画 加入第一帧 sf =SpriteFrameCache::getInstance()->getSpriteFrameByName("hero_fly_1.png"); anim->addSpriteFrame(sf); //加入第二帧 sf =SpriteFrameCache::getInstance()->getSpriteFrameByName("hero_fly_2.png"); anim->addSpriteFrame(sf); //设置帧循环播放次数 -1代表无限循环 anim->setLoops(-1); //设置帧播放的间隔 anim->setDelayPerUnit(0.01f); //根据anim序列创建anim动画an auto an =Animate::create(anim); //让飞机运行帧动画 this->runAction(an); }
int Torus::addValues(string attr, string val){ if(attr == "inner"){ setInnerRadius(atof(val.c_str())); }else{ if(attr == "outer"){ setOuterRadius(atof(val.c_str())); }else{ if(attr == "slices"){ setSlices(atoi(val.c_str())); }else{ if(attr == "loops"){ setLoops(atoi(val.c_str())); return 1; } } } } return 0; }
void Level01::animCache() { anim1 = Animation::create(); anim1->addSpriteFrameWithFileName("img/player02.png"); anim1->addSpriteFrameWithFileName("img/player03.png"); anim1->addSpriteFrameWithFileName("img/player04.png"); anim1->setLoops(1); anim1->setDelayPerUnit(0.2f); anim1->setRestoreOriginalFrame(true); auto standAnim = Animation::create(); standAnim->addSpriteFrameWithFileName("img/player01.png"); standAnim->addSpriteFrameWithFileName("img/player01-2.png"); standAnim->addSpriteFrameWithFileName("img/player01-3.png"); standAnim->setLoops(1); standAnim->setDelayPerUnit(0.7f); standAnim->setRestoreOriginalFrame(true); m_animCache = AnimationCache::getInstance(); m_animCache->addAnimation(anim1, "walking"); m_animCache->addAnimation(standAnim, "stand"); }
bool Thunder::init() { if (!Entity::init()) return false; auto animation = Animation::create(); //auto anisprite = Sprite::create("Thunder/Thunder_Picture.png"); //SpriteFrameCache::getInstance()->addSpriteFramesWithFile("Sprite/Thunder/Thunder_Picture.plist", anisprite->getTexture()); char szName[100]; for (int i = 1; i <= 10; ++i) { sprintf(szName, "Thunder/thunder%02d.png", i); animation->addSpriteFrameWithFile(szName); } animation->setDelayPerUnit(0.05); animation->setLoops(1); auto sprite = Sprite::create(); auto animate = Animate::create(animation); auto deadFunc = CallFunc::create([this]() { this->removeFromParent(); }); auto sequence = Sequence::create(animate, deadFunc, NULL); sprite->setScale(0.2); sprite->setAnchorPoint(Vec2(0.5, 0.05)); sprite->setPositionY(-20.0); sprite->runAction(sequence); this->addChild(sprite); this->scheduleUpdate(); return true; }
void CWaitingWindow::StartAnim() { Vector<SpriteFrame*> animFrames(12); std::string path = "";//animation/waiting/ for(int i = 1;i<=12;i++) { std::string framePath; if(i>9) { framePath = path + "0" + StringUtils::toString(i) + ".png"; } else { framePath = path + "00" + StringUtils::toString(i) + ".png"; } auto frame = SpriteFrame::create(framePath,Rect(0,0,64,64)); animFrames.pushBack(frame); } auto animation = CCAnimation::createWithSpriteFrames(animFrames,0.1); animation->setLoops(-1); m_AnimAction = CCAnimate::create(animation); m_AnimAction->setTag(ANIM_ACTION_TAG); m_AnimSprite->runAction(m_AnimAction); }
Bonus_3_12::Bonus_3_12(Node*scene,Vec2 pos) { string str = "cloud12.png"; initBase(); is_Bonus = true; Scene_UI*sce = (Scene_UI*)scene; menu = MenuItemSprite::create(Sprite::createWithSpriteFrameName(str), Sprite::createWithSpriteFrameName(str), [=](Ref*) { is_selected = !is_selected; if (is_selected) { for (int i = 0;i<sce->monster_queue.size();i++) { ; { ((Bonus_UI*)sce->monster_queue[i])->sprite_selected->setVisible(false); ((Bonus_UI*)sce->monster_queue[i])->is_selected = false; } } is_selected = true; sprite_selected->setVisible(true); return; } sprite_selected->setVisible(false); }); menu->setPosition(pos); menu;; men = Menu::create(menu, nullptr); men->setPosition(0, 0); scene->addChild(men); sprite = Sprite::createWithSpriteFrameName(str); scene->addChild(sprite); sprite->setPosition(pos); sprite;; sprite_selected = Sprite::createWithSpriteFrameName("point01.png"); { auto ani = Animation::create(); ani->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("point01.png")); ani->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("point02.png")); ani->setDelayPerUnit(3.0 / 30.0); ani->setRestoreOriginalFrame(false); ani->setLoops(-1); sprite_selected->runAction(Animate::create(ani)); } sprite_selected->setPosition(sprite->getContentSize().width / 2, sprite->getContentSize().height); sprite->addChild(sprite_selected); sprite_selected->setVisible(false); hp_sprite_2 = Sprite::createWithSpriteFrameName("MonsterHP02.png"); hp_sprite_2->setPosition(Vec2(sprite->getContentSize().width / 4, sprite->getContentSize().height - 5)); sprite->addChild(hp_sprite_2); hp_sprite_1 = Sprite::createWithSpriteFrameName("MonsterHP01.png"); hp_sprite_1->setPosition(Vec2(sprite->getContentSize().width / 4, sprite->getContentSize().height - 5)); sprite->addChild(hp_sprite_1); hp_sprite_1->setAnchorPoint(Vec2(0, 0.5)); hp_sprite_2->setAnchorPoint(Vec2(0, 0.5)); hp_sprite_1->setScaleY(0.7); sprite_effect_slow = Sprite::createWithSpriteFrameName("PShit-12.png"); sprite->addChild(sprite_effect_slow); auto ani1 = Animation::create(); ani1->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("PShit-12.png")); ani1->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("PShit-11.png")); ani1->setDelayPerUnit(0.1); ani1->setRestoreOriginalFrame(false); ani1->setLoops(-1); sprite_effect_slow->runAction(Animate::create(ani1)); sprite_effect_slow->setPosition(sprite->getContentSize().width / 2, 20); sprite_effect_slow->setVisible(false); hp_sprite_1->setVisible(false); hp_sprite_2->setVisible(false); /*init Õ¼ÓÃλÖÃ*/ queue_takeplace_pos.push_back(Vec2(PublicFunc::convertToX(pos.x),PublicFunc::convertToY(pos.y))); for (int i = 0;i<queue_takeplace_pos.size(); i++) { sce->data->push_back(queue_takeplace_pos[i]); } }
void Monster_UI::Destory(bool isKing) { Scene_UI*scen = (Scene_UI*)sprite->getParent(); playEffect(); /*清楚所有 该怪物 为目标的炮塔 目标*/ for (int i = 0; i < scen->tower_queue.size(); i++) { if (scen->tower_queue[i]->target == this) { scen->tower_queue[i]->setTarget(0); } } for (vector<Monster_UI*>::iterator it = scen->monster_queue.begin(); it != scen->monster_queue.end();) { if ((*it) == this) { scen->monster_queue.erase(it); } else ++it; } auto ani = Animation::create(); ani->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("air01.png")); ani->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("air02.png")); ani->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("air03.png")); ani->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("air04.png")); ani->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("air05.png")); ani->setDelayPerUnit(0.1); ani->setRestoreOriginalFrame(false); ani->setLoops(1); sprite->removeAllChildrenWithCleanup(true); sprite->stopAllActions(); char ss[100]; if (money >= 10) { sprintf(ss, "money%d.png", money); } else { sprintf(ss, "money0%d.png", money); } if (isKing) { bonus = Sprite::create(); } else { scen->view_up_menu->addMoney(money); bonus = Sprite::createWithSpriteFrameName(ss); } bonus->setPosition(sprite->getPosition()); sprite->getParent()->addChild(bonus, 6); bonus->runAction(MoveBy::create(0.2, Vec2(0, 50))); auto an = Animate::create(ani); /*q c*/ bonus;; sprite->runAction(Sequence::create(an, CallFunc::create([=] { sprite->removeFromParentAndCleanup(true); bonus->removeFromParentAndCleanup(true); delete this; }), nullptr)); }
void Tower_Pin::setLevel(int lev) { sprite->stopAllActions(); view_click = 0; switch (lev) { case 1: { sprite->setSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("Pin11.png")); sprite_base->setNormalImage(Sprite::createWithSpriteFrameName("Pin-11.png")); sprite_base->setSelectedImage(Sprite::createWithSpriteFrameName("Pin-11.png")); }break; case 2: { sprite->setSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("Pin21.png")); sprite_base->setNormalImage(Sprite::createWithSpriteFrameName("Pin-12.png")); sprite_base->setSelectedImage(Sprite::createWithSpriteFrameName("Pin-12.png")); }break; case 3: { sprite->setSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("Pin31.png")); sprite_base->setNormalImage(Sprite::createWithSpriteFrameName("Pin-13.png")); sprite_base->setSelectedImage(Sprite::createWithSpriteFrameName("Pin-13.png")); }break; } if (lev == 1) { auto ani = Animation::create(); ani->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("air11.png")); ani->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("air12.png")); ani->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("air13.png")); ani->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("air14.png")); ani->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("air15.png")); ani->setDelayPerUnit(0.07); ani->setRestoreOriginalFrame(true); ani->setLoops(1); /* BUG TMP FIX*/ if (effect == 0) { effect = Sprite::create(); effect->setPosition(sprite->getPosition()); sprite->getParent()->addChild(effect); effect->runAction(Animate::create(ani)); } else { effect->removeFromParentAndCleanup(true); effect = Sprite::create(); effect->setPosition(sprite->getPosition()); sprite->getParent()->addChild(effect); effect->runAction(Animate::create(ani)); } } else { //if (this->level < lev) { auto ani = Animation::create(); ani->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("air11.png")); ani->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("air12.png")); ani->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("air13.png")); ani->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("air14.png")); ani->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("air15.png")); ani->setDelayPerUnit(0.03); ani->setRestoreOriginalFrame(true); ani->setLoops(1); /* BUG TMP FIX*/ if (effect == 0) { effect = Sprite::create(); effect->setPosition(sprite->getPosition()); sprite->getParent()->addChild(effect); effect->runAction(Animate::create(ani)); } else { effect->removeFromParentAndCleanup(true); effect = Sprite::create(); effect->setPosition(sprite->getPosition()); sprite->getParent()->addChild(effect); effect->runAction(Animate::create(ani)); } } } this->level = lev; initTowerBase(); }
Tower_Rocket_Bullet::Tower_Rocket_Bullet(int lev, Node*p, float rotation, Vec2 pos_tower, Vec2 pos)/*scene ,属于某个tower ,目标位置*/ { isDone = false; string str = ""; float pos_x = 0, pos_y = 0; pos_y = 1200 * cos(rotation*3.14159 / 180.0); pos_x = 1200 * sin(rotation*3.14159 / 180.0); switch (lev) { case 1: { str = "PRocket11.png"; } break; case 2: { str = "PRocket21.png"; } break; case 3: { str = "PRocket31.png"; } break; } initTowerBulletBase(lev); sprite = Sprite::createWithSpriteFrameName(str); p->addChild(sprite); sprite->setPosition(pos_tower); sprite->runAction(MoveBy::create(1.8, Vec2(pos_x, pos_y))); sprite->setRotation(rotation); sprite;; switch (lev) { case 1: { str = "PRocket1"; } break; case 2: { str = "PRocket2"; } break; case 3: { str = "PRocket3"; } break; } auto ani = Animation::create(); ani->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName(str + "1.png")); ani->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName(str + "2.png")); ani->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName(str + "3.png")); ani->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName(str + "4.png")); ani->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName(str + "5.png")); ani->setDelayPerUnit(0.05); ani->setRestoreOriginalFrame(true); ani->setLoops(-1); sprite->runAction(Animate::create(ani)); }
void Monster_UI::set_effect_slow(int lev, int tag) { if (effect_slow_lev > lev)return;/*等级高的减速 才算*/ /*同等级 都会刷新减速时间*/ /*减速等级高优先*/ if (effect_slow_lev == 0) { sprite_effect_slow = Sprite::createWithSpriteFrameName("PShit-12.png"); sprite->addChild(sprite_effect_slow); auto ani1 = Animation::create(); ani1->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("PShit-12.png")); ani1->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("PShit-11.png")); ani1->setDelayPerUnit(0.1); ani1->setRestoreOriginalFrame(false); ani1->setLoops(-1); sprite_effect_slow->runAction(Animate::create(ani1)); sprite_effect_slow->setPosition(sprite->getContentSize().width / 2, 20); sprite_effect_slow->setVisible(false); } if (tag) { sprite_effect_slow->stopAllActions(); auto ani1 = Animation::create(); ani1->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("PShit-12.png")); ani1->addSpriteFrame(SpriteFrameCache::getInstance()->getSpriteFrameByName("PShit-11.png")); ani1->setDelayPerUnit(0.1); ani1->setRestoreOriginalFrame(false); ani1->setLoops(-1); sprite_effect_slow->runAction(Animate::create(ani1)); sprite_effect_slow->setPosition(sprite->getContentSize().width / 2, 20); } effect_slow_lev = lev; moveSpeed = moveSpeed_readOnly; is_effect_slow = true; sprite_effect_slow->setVisible(true); switch (lev) { case 1: { moveSpeed /= 0.8; } break; case 2: { moveSpeed /= 0.6; } break; case 3: { moveSpeed /= 0.3; } break; } isDone = true; sprite->stopActionByTag(2); sprite->stopActionByTag(3); sprite->stopActionByTag(4); auto a4 = Sequence::create(DelayTime::create(1.0 + 0.5*lev), CallFunc::create([=]() { is_effect_slow = false; moveSpeed = moveSpeed_readOnly; isDone = true; sprite_effect_slow->setVisible(false); sprite->stopActionByTag(2); sprite->stopActionByTag(3); sprite->stopActionByTag(4); effect_slow_lev = 0; updateWay(); }), nullptr); a4->setTag(4); sprite->runAction(a4); }
bool Stage1::init() { /*_effect = LightEffect::create(); _effect->retain(); Vec3 lightPos(200, 200, 100); _effect->setLightPos(lightPos); _effect->setLightCutoffRadius(5000); _effect->setBrightness(2.0);*/ //map->setEffect(_effect, "title_n.png"); //map->initTileMap(); /*map = MapLayer::create(); bulletLayer = BulletLayer::create(); main = (MainFly*)MainFly::myCreate("main.png"); warrior = (Warrior*)Warrior::create("sprite_1.png"); warrior->setName("Warrior"); auto weapon = (Weapon*)Weapon::create("weapon1.png"); warrior->setWeapon(weapon);*/ /*std::string arrFile[] = { "up.png", "left.png", "right.png" }; Vec2 arrPos[] = { Vec2(48 + 96, 48 + 96), Vec2(48, 48), Vec2(48 + 96 * 2, 48), Vec2(800, 48 + 96) }; for (int i = 0; i < 4; i++){ auto arr = Input::create("arr.png", Rect(i * 96, 0, 96, 96)); arr->setTag(i); arr->setPosition(arrPos[i]); arr->setControllee(warrior); inputs.push_back(arr); this->addChild(arr, 20); } warrior->setPosition(Vec2(oriX, oriY)); //warrior->setWorldPosition(Vec2(oriX, oriY)); //warrior->setEffect(_effect, "warrior_n.png"); for (int i = 0; i < 21; i++) { auto skull = Skull::myCreate("skull1.png"); skull->setPosition(Vec2(oriX*(i), oriY)); skull->setName("skull"); //skull->setEffect(_effect, "warrior_n.png"); auto skullWeapon = SkullWeapon::create("skullWeapon.png"); map->addChild(skullWeapon, 10); skull->setWeapon(skullWeapon); map->addChild(skull, 10); } mainPos = Vec2(100, 100); main->setPosition(mainPos);*/ //auto enemy = (Enemy*)Enemy::myCreate("main.png"); //enemy->enemyWeakUp(this); /*warrior->scheduleUpdate(); map->scheduleUpdate(); this->scheduleUpdate(); auto touchListener = EventListenerTouchOneByOne::create(); touchListener->onTouchBegan = CC_CALLBACK_2(Stage1::onTouchBegan, this); touchListener->onTouchEnded = CC_CALLBACK_2(Stage1::onTouchEnded, this); touchListener->onTouchMoved = CC_CALLBACK_2(Stage1::onTouchMoved, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(touchListener, this);*/ /*CocosDenshion::SimpleAudioEngine::getInstance()->preloadBackgroundMusic("bgm/01.mp3"); CocosDenshion::SimpleAudioEngine::getInstance()->playBackgroundMusic("bgm/01.mp3", true); map1 = Sprite::create("pixel_art_landscape_by_mockingjay1701-d8omc3c.png"); Vec2 map1Pos = Vec2(0 + map1->getContentSize().width / 2, 0 + map1->getContentSize().height / 10); map1->setPosition(map1Pos); trees = Sprite::create("trees.png"); Vec2 treesPos = Vec2(0 + trees->getContentSize().width / 2, 0 + trees->getContentSize().height - 200); trees->setPosition(treesPos); ParticleSystemQuad* mSystem = ParticleSystemQuad::create("test.plist"); mSystem->setTextureWithRect(TextureCache::sharedTextureCache()->addImage("8.png"), Rect(0, 0, 64, 64)); mSystem->setBlendAdditive(true); mSystem->setPosition(ccp(0, 540));*/ /*this->addChild(map, 2); this->addChild(bulletLayer, 1); map->addChild(weapon, 5); map->addChild(warrior, 5); this->addChild(main, 10); this->addChild(map1, 0); this->addChild(trees, 1); this->addChild(mSystem, 50);*/ this->schedule(schedule_selector(Stage1::loadingsStep), 0.1f); auto loadingAmimation = Sprite::create("loadingAnimation.png", Rect(0, 0, 256, 256)); Vector<SpriteFrame*> animFrames(4); for (int i = 1; i < 4; i++) { auto frame = SpriteFrame::create("loadingAnimation.png", Rect(256 * i, 0, 256, 256)); animFrames.pushBack(frame); } auto animation = Animation::createWithSpriteFrames(animFrames, 0.1f); animation->setLoops(-1); auto animate = Animate::create(animation); //loadingAmimation->stopAllActions(); loadingAmimation->runAction(animate); loadingAmimation->setPosition(Vec2(960 / 2, 540 / 2)); loadingAmimation->setName("loadingAnimation"); this->addChild(loadingAmimation, 60); auto loadingBack = Sprite::create(); loadingBack->setColor(Color3B(255, 255, 255)); this->addChild(loadingBack, 69); return true; }