void ShowLayer::useFZPower(Vec2 pt) { //点击粒子特效 CCParticleSystemQuad *mParticle = CCParticleSystemQuad::create("showClick.plist"); mParticle->setScale(0.5f); mParticle->setPosition(pt); //如果不设置,粒子播放后内存不释放 mParticle->setAutoRemoveOnFinish(true); this->addChild(mParticle); Size visibleSize = Director::getInstance()->getVisibleSize(); Vec2 pt2; pt2.x = (pt.x - visibleSize.width / 2) < 0 ? -5 : 5; pt2.y = (pt.y - visibleSize.height / 2) < 0 ? -5 : 5; auto action = MoveTo::create(0.2f, pt2); auto action2 = MoveTo::create(0.5f, Vec2(-pt2.x, -pt2.y)); auto action3 = ScaleTo::create(0.2f, 1.1f); auto action4 = ScaleTo::create(0.5f, 1.0f); //屏幕震动特效 this->m_Map->runAction(Sequence::create(Spawn::create(action, action3, NULL), Spawn::create(action2, action4, NULL), NULL)); //使用人物技能 m_PlayerManager->useFZ(pt, m_MonsterManager->getMonsterList(), m_BossManager->getboss(), m_FirePower); }
// The kaboom stuff void InGamePowers::OnFreezeBallHit(CCNode* sender) { // Do all the magic here mCurrentActiveTroll->mFreezedTime = 10;//Get from missions some param? // Remove the indicator ? if(mCurrentActiveTroll->getChildByTag(TROLL_WTF_INDICATOR)!=NULL){ mCurrentActiveTroll->removeChildByTag(TROLL_WTF_INDICATOR); } // Add for now blue troll FX mCurrentActiveTroll->_animation->setColor(ccc3(0, 164, 255)); // Remove the ball if(mGameScene->getChildByTag(FLY_BALL_MASTER_TROLL)!=NULL){ mGameScene->removeChildByTag(FLY_BALL_MASTER_TROLL); } // Create some particles and sound ??? CCParticleSystemQuad* p = CCParticleSystemQuad::create("Particles/bullet_explode.plist"); p->setPosition(mCurrentActiveTroll->getPositionX(), mCurrentActiveTroll->getPositionY()); p->setAutoRemoveOnFinish(true); mGameScene->addChild(p,5002); mGameScene->playInGameSound("dwarf_crash"); // Clear it mCurrentActiveTroll = NULL; // Reset the correct button? button_2->setEnabled(true); button_2->setOpacity(255); }
void GameScene::updateProjectiles(float dt) { if (m_bullets->count() > 0) { CCObject* ob = NULL; CCARRAY_FOREACH(m_bullets, ob) { Projectile* proj = dynamic_cast<Projectile*>(ob); proj->update(dt); if (proj->getPositionX() < 0.f - proj->getContentSize().width || proj->getPositionX() > m_visibleSize.width + proj->getContentSize().width) m_removableBullets->addObject(proj); else if (checkCollisions(m_hero, proj) && proj->getType() == Projectile::Bullet) { m_removableBullets->addObject(proj); updateHealth(10); // dmg value here } else { for (uint i = 0; i < m_enemies->count(); ++i) { Enemy* en = dynamic_cast<Enemy*>(m_enemies->objectAtIndex(i)); if (checkCollisions(en, proj) && proj->getType() == Projectile::Rocket) { m_removableBullets->addObject(proj); m_removables->addObject(m_enemies->objectAtIndex(i)); CCParticleSystemQuad * smokeParticle = CCParticleSystemQuad::create("textures/smoke.plist"); smokeParticle->setPosition(en->getPosition()); this->addChild(smokeParticle); smokeParticle->setAutoRemoveOnFinish(true); CCParticleSystemQuad * dustParticle = CCParticleSystemQuad::create("textures/dusts.plist"); dustParticle->setPosition(en->getPosition()); this->addChild(dustParticle); dustParticle->setAutoRemoveOnFinish(true); CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("audio/rocketExplode.wav", false); CocosDenshion::SimpleAudioEngine::sharedEngine()->playEffect("audio/enemyKill.wav", false); updateScore(); //score value here } } } }
void MagicWitch::RunParticle() { CCParticleSystemQuad *particle = CCParticleSystemQuad::create( "witch0.plist"); particle->setDuration(2.0f); particle->setPosition(ccp( particle->getPositionX() * SCALE_X, particle->getPositionY() * SCALE_Y)); particle->setScale(BUTTON_SCALE); particle->setAutoRemoveOnFinish(true); my_layer_->getParent()->addChild(particle, gameconfig::WITCH_ANIM_NODE_ZORDER); }
bool RigidBlock::tryLaunchParticle(CCPoint emitPoint) { CCParticleSystemQuad *particle = CCParticleSystemQuad::create("NewBlockParticle_1.plist"); particle->setAnchorPoint(ccp(0.5f, 0.5)); particle->setPosition(m_position); particle->setAutoRemoveOnFinish(true); this->addChild(particle); return true; }
void Box::playBurst(CCNode* sender, void* data) { Tile2 *tile = static_cast<Tile2 *>(data); CCLOG("Scaling tile %d,%d with delay %f", tile->x, tile->y); CCFiniteTimeAction *action = CCSequence::create( CCScaleTo::create(0.3f, 0.0f), CCCallFuncN::create(this, callfuncN_selector(Box::removeSprite)), NULL ); tile->sprite->runAction(action); // Add the balloon burst effect CCParticleSystemQuad *burst = CCParticleSystemQuad::create(burst_effect_filename.c_str()); burst->setPosition(tile->pixPosition()); burst->setAutoRemoveOnFinish(true); layer->addChild(burst); }
bool BlackHoleEffectTest::ccTouchBegan(CCTouch* touch, CCEvent* event) { CCParticleSystemQuad* blackHoleParticle = CCParticleSystemQuad::create("blackHoleEffect.plist"); blackHoleParticle->setPosition(touch->getLocation()); blackHoleParticle->setAutoRemoveOnFinish(true); this->addChild(blackHoleParticle); BlackHoleEffect* bh = BlackHoleEffect::create(); bh->setInHoleSelector(this, in_hole_selector(BlackHoleEffectTest::inHoleComplete)); bh->setAttenuationSelector(this, attenuation_selector(BlackHoleEffectTest::attenuationComplete)); bh->setOverSelector(this, over_selector(BlackHoleEffectTest::overComplete)); bh->setUserObject(blackHoleParticle); bh->addSubstanceList(this->objList); bh->addHole(touch->getLocation().x, touch->getLocation().y); this->ary->addObject(bh); return true; }
CCParticleSystemQuad* ParticleManagerX::getParticle(const char *name) { CCAssert(name && strlen(name) > 0, "!!! ParticleManager::getParticle(name) name is invalid"); if (!name || strlen(name) <= 0) { return NULL; } CCParticleSystemQuad *particle = NULL; for(ParticleEmittersMap::iterator it = this->m_ParticleEmittersMap.begin(); it != this->m_ParticleEmittersMap.end(); it++) { ParticleEmitters *emitters = (ParticleEmitters*)(it->second); if (emitters && name) { particle = emitters->getParticle(name); } if (particle) { particle->setAutoRemoveOnFinish(true); break; } } return particle; }
void Player::Die() { // first reduce lives lives_ = (--lives_ < 0) ? 0 : lives_; // respawn only if there are lives remaining is_respawning_ = (lives_ > 0); // animate the death :( CCActionInterval* death = CCSpawn::createWithTwoActions(CCFadeOut::create(0.5f), CCScaleTo::create(0.5f, 1.5f)); // call the appropriate callback based on lives remaining CCActionInstant* after_death = (lives_ <= 0) ? (CCCallFunc::create(this, callfunc_selector(Player::OnAllLivesFinished))) : (CCCallFunc::create(this, callfunc_selector(Player::Respawn))); runAction(CCSequence::createWithTwoActions(death, after_death)); // play a particle...a sad one :( CCParticleSystemQuad* explosion = CCParticleSystemQuad::create("explosion.plist"); explosion->setAutoRemoveOnFinish(true); explosion->setPosition(m_obPosition); game_world_->addChild(explosion); SOUND_ENGINE->playEffect("blast_player.wav"); }
void LoginLayer::_initComponent() { CCSize size = CCDirector::sharedDirector()->getVisibleSize(); /* 大游戏之名字 */ CCSprite* nameOfGame = CCSprite::create("GAME_NAME.png"); nameOfGame->setPosition(ccp(size.width / 2, size.height - 120)); addChild(nameOfGame, 10); /* 可移动背景 */ srand( (unsigned)time( NULL ) ); int x = rand() % 2; int y = rand() % 1500; CCSprite* pLoginBg = CCSprite::create("bg_big.png"); pLoginBg->setAnchorPoint(CCPointZero); pLoginBg->setPosition(ccp(-y/*(LOGIN_BG_WIDTH - size.width) / 2*/, 0)); this->addChild(pLoginBg); if (x == 0) { CCActionInterval * move = CCMoveTo::create(LOGIN_BG_TIME, ccp(size.width - LOGIN_BG_WIDTH, 0)); CCActionInterval * move1 = CCMoveTo::create(LOGIN_BG_TIME, ccp(0, 0)); CCFiniteTimeAction * seq= CCSequence::create(move, move1, NULL); CCActionInterval * repeatForever =CCRepeatForever::create((CCActionInterval* )seq); pLoginBg->runAction(repeatForever); } else if (x == 1) { CCActionInterval * move = CCMoveTo::create(LOGIN_BG_TIME, ccp(0, 0)); CCActionInterval * move1 = CCMoveTo::create(LOGIN_BG_TIME, ccp(size.width - LOGIN_BG_WIDTH, 0)); CCFiniteTimeAction * seq= CCSequence::create(move, move1, NULL); CCActionInterval * repeatForever =CCRepeatForever::create((CCActionInterval* )seq); pLoginBg->runAction(repeatForever); } /* 效果火焰 */ CCParticleSystemQuad* particle = CCParticleSystemQuad::create("dzt3.plist"); particle->setAnchorPoint(CCPointZero); particle->setPosition(ccp(320, 0)); particle->setScaleX(0.9); particle->setAutoRemoveOnFinish(true); addChild(particle, 11); /* 火星 */ CCParticleSystemQuad* particlefire = CCParticleSystemQuad::create("firefly.plist"); particlefire->setAnchorPoint(CCPointZero); particlefire->setPosition(ccp(0, 800)); particlefire->setAutoRemoveOnFinish(true); addChild(particlefire, 11); /* 火星1 */ CCParticleSystemQuad* particlefire1 = CCParticleSystemQuad::create("firefly2.plist"); particlefire1->setAnchorPoint(CCPointZero); particlefire1->setPosition(ccp(0, 800)); particlefire1->setAutoRemoveOnFinish(true); addChild(particlefire1, 11); /* 开始游戏按钮 */ CCMenuItemImage *pLoginBtn = CCMenuItemImage::create( "pre.png", "def.png", this, menu_selector(LoginLayer::gameInit)); pLoginBtn->setAnchorPoint(ccp(0.5, 0)); pLoginBtn->setPosition(ccp(size.width / 2, 70)); CCMenu* pLoginMenu = CCMenu::create(pLoginBtn, NULL); pLoginMenu->setAnchorPoint(CCPointZero); pLoginMenu->setPosition(CCPointZero); this->addChild(pLoginMenu); CCSprite* startFont = CCSprite::create("start.png"); startFont->setAnchorPoint(ccp(0.5, 0)); startFont->setPosition(ccp(size.width / 2, 115)); this->addChild(startFont); CCActionInterval * scale = CCScaleTo::create(1, 1.2); CCActionInterval * scale1 = CCScaleTo::create(1.5, 1); CCFiniteTimeAction * seq= CCSequence::create(scale,scale1,NULL); CCActionInterval * repeatForever =CCRepeatForever::create((CCActionInterval* )seq); startFont->runAction(repeatForever); /* 服务器列表滚动视图 */ /* m_scrollView = CCScrollView::create(VIEW_SIZE); m_scrollView->setViewSize(VIEW_SIZE); m_scrollView->setContentSize(CCSizeMake(62*5, VIEW_SIZE.height)); m_scrollView->setAnchorPoint(ccp(0, 0)); m_scrollView->setPosition(SCROLLVIEW_OFFSETX, OFFSET_1136 + SCROLLVIEW_OFFSETY); m_scrollView->setDirection(kCCScrollViewDirectionHorizontal); m_scrollView->setBounceable(true); m_scrollView->setDelegate(this); this->addChild(m_scrollView); */ for (int i = 0; i < 5; ++i) { CCMenuItemImage *pSvrBtn = CCMenuItemImage::create( "LG_nor.png", "LG_nor.png", this, menu_selector(LoginLayer::option)); pSvrBtn->setTag(SVRBG_NORMAL + i); pSvrBtn->setAnchorPoint(ccp(0, 0)); pSvrBtn->setPosition(ccp(SCROLLVIEW_OFFSETX + 60 * i, m_pGameState->getBottomOffset() + SCROLLVIEW_OFFSETY)); CCMenu* pMenu = CCMenu::create(pSvrBtn, NULL); pMenu->setAnchorPoint(ccp(0, 0)); pMenu->setPosition(ccp(0, 0)); this->addChild(pMenu); /* 服务器名字 */ CCLabelTTF* svrName = CCLabelTTF::create("", "Arial", 30, CCSizeMake(35, 300), kCCTextAlignmentCenter); svrName->setAnchorPoint(ccp(0.5, 0)); svrName->setColor(ccc3(255, 215, 0)); svrName->setPosition(ccp(SCROLLVIEW_OFFSETX + 37.0f + 60.0f * i, m_pGameState->getBottomOffset() + SCROLLVIEW_OFFSETY + 75.0f)); this->addChild(svrName, 2, SVR_NAME + i); /* 选中背景状态 */ CCSprite* pSvrBtnBg = CCSprite::create("LG_sel.png"); pSvrBtnBg->setAnchorPoint(ccp(0, 0)); pSvrBtnBg->setPosition(ccp(SCROLLVIEW_OFFSETX + 60.0f * i, m_pGameState->getBottomOffset() + SCROLLVIEW_OFFSETY - 10.0f)); pSvrBtnBg->setVisible(false); this->addChild(pSvrBtnBg, 1, SVRBG_SELECT + i); } unsigned int server_id = CCUserDefault::sharedUserDefault()->getIntegerForKey(LOGIN_SERVER_KEY, 0); /* 更改服务器名 */ if (0 == server_id) { CCLabelTTF* svrName = (CCLabelTTF*)this->getChildByTag(SVR_NAME); svrName->setScale(1.1); svrName->setString("体验服务器"); CCLabelTTF* svrName1 = (CCLabelTTF*)this->getChildByTag(SVR_NAME+1); svrName1->setString("研发服务器"); m_serverid[0] = 0; m_serverid[1] = 1; CCSprite* sp = (CCSprite*)this->getChildByTag(SVRBG_SELECT); /*默认第一个选中*/ sp->setVisible(true); } else { CCLabelTTF* svrName = (CCLabelTTF*)this->getChildByTag(SVR_NAME); svrName->setString("体验服务器"); CCLabelTTF* svrName1 = (CCLabelTTF*)this->getChildByTag(SVR_NAME + 1); svrName1->setString("研发服务器"); svrName1->setScale(1.1); m_serverid[0] = 0; m_serverid[1] = 1; CCSprite* sp1 = (CCSprite*)this->getChildByTag(SVRBG_SELECT + 1); sp1->setVisible(true); } /* 登陆框,待改善 */ // 取出存储的用户 id std::string strUserId = CCUserDefault::sharedUserDefault()->getStringForKey(USER_NAME_KEY); LoginBox* login = LoginBox::create(); login->setPosition(ccp(100, 200)); login->setContent(strUserId); addChild(login, 100, LOGIN_ID_TAG); }