CCParticleSystem* ADParticleSystemCache::addParticleSystem( const char *pFileName ) { CCParticleSystem *pRetPart = NULL; ParticleSystemBatchMap::iterator iter = m_particleBatchesIdle.find( pFileName ); if( iter == m_particleBatchesIdle.end() ) { pRetPart = CCParticleSystemQuad::create( pFileName ); CCParticleBatchNode *pNode = CCParticleBatchNode::createWithTexture( pRetPart->getTexture(), 100 ); m_pRootNode->addChild( pNode ); pNode->addChild( pRetPart ); m_particleBatchesUsed[pFileName]._pBatchNode = pNode; m_particleBatchesIdle[pFileName]._pBatchNode = pNode; } else { if( iter->second._particleSystems.empty() ) { pRetPart = _createNewParticleSystem( pFileName, iter->second._pBatchNode ); iter->second._particleSystems.push_back( pRetPart ); } else { pRetPart = iter->second._particleSystems.front(); iter->second._particleSystems.pop_front(); } } CCAssert( pRetPart != NULL, " add particle system error " ); m_particleBatchesUsed[pFileName]._particleSystems.push_back( pRetPart ); return pRetPart; }
// override removeChild: void CCParticleBatchNode::removeChild(CCNode* child, bool cleanup) { // explicit nil handling if (child == NULL) { return; } CCAssert( dynamic_cast<CCParticleSystem*>(child) != NULL, "CCParticleBatchNode only supports CCQuadParticleSystems as children"); CCAssert(m_pChildren->containsObject(child), "CCParticleBatchNode doesn't contain the sprite. Can't remove it"); CCParticleSystem* pChild = (CCParticleSystem*)child; CCNode::removeChild(pChild, cleanup); // remove child helper m_pTextureAtlas->removeQuadsAtIndex(pChild->getAtlasIndex(), pChild->getTotalParticles()); // after memmove of data, empty the quads at the end of array m_pTextureAtlas->fillWithEmptyQuadsFromIndex(m_pTextureAtlas->getTotalQuads(), pChild->getTotalParticles()); // particle could be reused for self rendering pChild->setBatchNode(NULL); updateAllAtlasIndexes(); }
//------------------------------------------------------------------ // // SchedulerTest // //------------------------------------------------------------------ void SchedulerTest::onEnter() { EaseSpriteDemo::onEnter(); // rotate and jump CCActionInterval* jump1 = CCJumpBy::actionWithDuration(4, CCPointMake(-400,0), 100, 4); CCActionInterval* jump2 = jump1->reverse(); CCActionInterval* rot1 = CCRotateBy::actionWithDuration(4, 360*2); CCActionInterval* rot2 = rot1->reverse(); CCFiniteTimeAction* seq3_1 = CCSequence::actions(jump2, jump1, NULL); CCFiniteTimeAction* seq3_2 = CCSequence::actions( rot1, rot2, NULL); CCFiniteTimeAction* spawn = CCSpawn::actions(seq3_1, seq3_2, NULL); CCFiniteTimeAction* action = CCRepeatForever::actionWithAction((CCActionInterval*)spawn); CCRepeatForever* action2 = (CCRepeatForever*)(action->copy()->autorelease()); CCRepeatForever* action3 = (CCRepeatForever*)(action->copy()->autorelease()); m_grossini->runAction( CCSpeed::actionWithAction((CCActionInterval*)action, 0.5f) ); m_tamara->runAction( CCSpeed::actionWithAction((CCActionInterval*)action2, 1.5f) ); m_kathia->runAction( CCSpeed::actionWithAction((CCActionInterval*)action3, 1.0f) ); CCParticleSystem* emitter = CCParticleFireworks::node(); emitter->setTexture(CCTextureCache::sharedTextureCache()->addImage("Images/fire.png")); addChild(emitter); //sliderCtl = [self sliderCtl]; //[[[[Director sharedDirector] openGLView] window] addSubview: sliderCtl]; }
void Role::skillAction(SkillState sk){ switch (sk) { case Skill_Blood:{ SimpleAudioEngine::sharedEngine()->playEffect(S_BLOOD); CCParticleSystem* particle = CCParticleSystemQuad::create("Teleport.plist"); particle->setStartColor(ccc4f(0.5, 0.5, 0.5, 1)); particle->setPosition(this->getObjPosition()); GameLogic::Singleton()->getPView()->addChild(particle,99,Blood_Particle_Tag); float bloodValue = GameLogic::Singleton()->getBlood(); GameLogic::Singleton()->setBlood(bloodValue += bloodValue * 0.1);//10% CCLOG("+=================Blood Skill Open===============+"); } break; case Skill_Sprint:{ int deltaTime = 2.0f; if (_skState == Skill_Sprint) deltaTime += 2.0f; else _skState = Skill_Sprint; this->setObjRotation(0); SimpleAudioEngine::sharedEngine()->playEffect(S_SPRINT); CCParticleSystem* particle = CCParticleSystemQuad::create("Sprint.plist"); particle->setPosition(ccpAdd(this->getObjPosition(),ccp(30,0))); GameLogic::Singleton()->getPView()->addChild(particle,99,Sprint_Tag); _standardPoint.x = 200; this->runAction(CCSequence::create(CCDelayTime::create(deltaTime), CCCallFuncND::create(this,callfuncND_selector(Role::sprintFunc),this), NULL)); } break; case Skill_Wave:{ SimpleAudioEngine::sharedEngine()->playEffect(S_WAVE); this->deleteObjectsInWave(); CCSprite* waveSpr = CCSprite::createWithSpriteFrameName("Wave.png"); waveSpr->setScale(0.1f); waveSpr->setPosition(ccp(15, 15)); CCSpawn* spawnAction = CCSpawn::create(CCScaleTo::create(0.5f, 1.5f), CCFadeOut::create(0.5f), NULL); CCSequence* sequceceAction = CCSequence::create(spawnAction, CCCallFuncND::create(this, callfuncND_selector(Role::waveFunc),this), NULL); CCSpeed* aSpeed = CCSpeed::create(sequceceAction, 2.5f); waveSpr->runAction(aSpeed); this->addChild(waveSpr,99,Wave_Tag); } break; default: break; } }
CCParticleSystem* ParticleLayer::createPhoenix() { CCParticleSystem *emitter = new CCParticleSystemQuad(); emitter->initWithFile("Particles/Phoenix.plist"); addChild(emitter, 10); return emitter; }
void ParticleLayer::gravityShock(CCObject *pdata) { CCDictionary *dict = dynamic_cast<CCDictionary*>(pdata); float x = dynamic_cast<CCFloat*>(dict->objectForKey("x"))->getValue(); float y = dynamic_cast<CCFloat*>(dict->objectForKey("y"))->getValue(); CCParticleSystem *emitter = createExplodingRing(); emitter->setPosition(ccp(x, y)); }
void ParticleMainScene::step(float dt) { CCLabelAtlas *atlas = (CCLabelAtlas*) getChildByTag(kTagLabelAtlas); CCParticleSystem *emitter = (CCParticleSystem*) getChildByTag(kTagParticleSystem); char str[10] = {0}; sprintf(str, "%4d", emitter->getParticleCount()); atlas->setString(str); }
CCParticleSystem* ParticleLayer::createFireParticle() { CCParticleSystem *emitter = CCParticleFire::create(); emitter->retain(); addChild(emitter, 10); emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage("Particles/fire.png") ); return emitter; }
IntervalLayer::IntervalLayer() { m_time0 = m_time1 = m_time2 = m_time3 = m_time4 = 0.0f; CCSize s = CCDirector::sharedDirector()->getWinSize(); // sun CCParticleSystem* sun = CCParticleSun::node(); sun->setTexture(CCTextureCache::sharedTextureCache()->addImage("Images/fire.png")); sun->setPosition( CCPointMake(s.width-32,s.height-32) ); sun->setTotalParticles(130); sun->setLife(0.6f); this->addChild(sun); // timers m_label0 = CCLabelBMFont::labelWithString("0", "fonts/bitmapFontTest4.fnt"); m_label1 = CCLabelBMFont::labelWithString("0", "fonts/bitmapFontTest4.fnt"); m_label2 = CCLabelBMFont::labelWithString("0", "fonts/bitmapFontTest4.fnt"); m_label3 = CCLabelBMFont::labelWithString("0", "fonts/bitmapFontTest4.fnt"); m_label4 = CCLabelBMFont::labelWithString("0", "fonts/bitmapFontTest4.fnt"); scheduleUpdate(); schedule(schedule_selector(IntervalLayer::step1)); schedule(schedule_selector(IntervalLayer::step2), 0); schedule(schedule_selector(IntervalLayer::step3), 1.0f); schedule(schedule_selector(IntervalLayer::step4), 2.0f); m_label0->setPosition(CCPointMake(s.width*1/6, s.height/2)); m_label1->setPosition(CCPointMake(s.width*2/6, s.height/2)); m_label2->setPosition(CCPointMake(s.width*3/6, s.height/2)); m_label3->setPosition(CCPointMake(s.width*4/6, s.height/2)); m_label4->setPosition(CCPointMake(s.width*5/6, s.height/2)); addChild(m_label0); addChild(m_label1); addChild(m_label2); addChild(m_label3); addChild(m_label4); // Sprite CCSprite* sprite = CCSprite::spriteWithFile(s_pPathGrossini); sprite->setPosition( CCPointMake(40,50) ); CCJumpBy* jump = CCJumpBy::actionWithDuration(3, CCPointMake(s.width-80,0), 50, 4); addChild(sprite); sprite->runAction( CCRepeatForever::actionWithAction( (CCActionInterval*)(CCSequence::actions(jump, jump->reverse(), NULL )) ) ); // pause button CCMenuItem* item1 = CCMenuItemFont::itemFromString("Pause", this, menu_selector(IntervalLayer::onPause) ); CCMenu* menu = CCMenu::menuWithItems(item1, NULL); menu->setPosition( CCPointMake(s.width/2, s.height-50) ); addChild( menu ); }
void CCDisplayFactory::updateParticleDisplay(CCBone *bone, CCNode *display, float dt, bool dirty) { CCParticleSystem *system = (CCParticleSystem *)display; CCBaseData node; CCTransformHelp::matrixToNode(bone->nodeToArmatureTransform(), node); system->setPosition(node.x, node.y); system->setScaleX(node.scaleX); system->setScaleY(node.scaleY); system->update(dt); }
void CS_DISPLAY_PARTICLE_UPDATE(Bone *bone, DecorativeDisplay *decoDisplay, float dt, bool dirty) { CCParticleSystem *system = (CCParticleSystem*)decoDisplay->getDisplay(); Node node; TransformHelp::matrixToNode(bone->nodeToArmatureTransform(), node); system->setPosition(node.x, node.y); system->setScaleX(node.scaleX); system->setScaleY(node.scaleY); system->update(dt); }
//rebuild atlas indexes void CCParticleBatchNode::updateAllAtlasIndexes() { CCObject *pObj = NULL; unsigned int index = 0; CCARRAY_FOREACH(m_pChildren,pObj) { CCParticleSystem* child = (CCParticleSystem*)pObj; child->setAtlasIndex(index); index += child->getTotalParticles(); }
CCParticleSystem * CCParticleSystem::create(const char *plistFile) { CCParticleSystem *pRet = new CCParticleSystem(); if (pRet && pRet->initWithFile(plistFile)) { pRet->autorelease(); return pRet; } CC_SAFE_DELETE(pRet); return pRet; }
CCParticleSystem* ParticleLayer::createMeteor() { CCParticleSystem *emitter = CCParticleMeteor::create(); emitter->retain(); addChild(emitter, 10); emitter->setGravity(CCPointZero); emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage("Particles/fire.png") ); return emitter; }
CCParticleSystem* ParticleLayer::createExplodingRing() { CCParticleSystem *emitter = new CCParticleSystemQuad(); emitter->initWithFile("Particles/ExplodingRing.plist"); emitter->setAutoRemoveOnFinish(true); // emitter->setEndRadius(100.0f); addChild(emitter, 10); return emitter; }
CCParticleSystem* ParticleLayer::createGalaxy() { CCParticleSystem *emitter = new CCParticleSystemQuad(); emitter->initWithFile("Particles/Galaxy.plist"); //CCParticleSystem *emitter = CCParticleGalaxy::create(); //emitter->retain(); //emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage("Particles/fire.png") ); addChild(emitter, 10); return emitter; }
CCParticleSystem* CCParticleSystem::createWithTotalParticles(unsigned int numberOfParticles) { CCParticleSystem *pRet = new CCParticleSystem(); if (pRet && pRet->initWithTotalParticles(numberOfParticles)) { pRet->autorelease(); return pRet; } CC_SAFE_DELETE(pRet); return pRet; }
void TestParticle::initSpiral() { CCParticleSystem *emitter = CCParticleSpiral::create(); emitter->retain(); addChild(emitter,10); emitter->setTexture(CCTextureCache::sharedTextureCache()->addImage("fire.png")); emitter->setPosition(ccp(250,50)); emitter->release(); }
void StarPuzzle::clearPuzzle() { for (int i = 0; i < m_size; i++) { if (m_stars[i] != NULL) { delete m_stars[i]; m_stars[i] = NULL; } } CCObject* it = NULL; CCARRAY_FOREACH(m_emitterArray, it) { CCParticleSystem *emitter = dynamic_cast<CCParticleSystem*>(it); emitter->removeFromParent(); }
/** * If the particle system has exhausted and it is set to auto-remove, remove this * node from the scene so that this node and the particle system will be released. */ void CC3ParticleSystemBillboard::updateBeforeTransform( CC3NodeUpdatingVisitor* visitor ) { if ( m_pBillboard ) { CCParticleSystem* ps = (CCParticleSystem*)m_pBillboard; if ( ps->isAutoRemoveOnFinish() && !ps->isActive() && ps->getParticleCount() == 0 ) { CC3_TRACE("[bbd]2D particle system exhausted. Removing"); visitor->requestRemovalOf( this ); } } }
CCParticleSystem* ParticleLayer::createExplosion() { CCParticleSystem *emitter = CCParticleExplosion::create(); emitter->retain(); addChild(emitter, 10); emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage("Particles/stars.png") ); emitter->setAutoRemoveOnFinish(true); return emitter; }
CCParticleSystem* ParticleLayer::createFireWorks() { CCParticleSystem *emitter = CCParticleFireworks::create(); emitter->retain(); emitter->setGravity(CCPointZero); addChild(emitter, 10); emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage("Particles/stars.png") ); emitter->setAutoRemoveOnFinish(true); return emitter; }
void CCDisplayFactory::createParticleDisplay(CCBone *bone, CCDecorativeDisplay *decoDisplay) { CCParticleDisplayData *displayData = (CCParticleDisplayData *)decoDisplay->getDisplayData(); CCParticleSystem *system = CCParticleSystemQuad::create(displayData->displayName.c_str()); system->removeFromParent(); CCArmature *armature = bone->getArmature(); if (armature) { system->setParent(bone->getArmature()); } decoDisplay->setDisplay(system); }
// Reorder will be done in this function, no "lazy" reorder to particles void CCParticleBatchNode::reorderChild(CCNode * child, int zOrder) { CCAssert( child != NULL, "Child must be non-NULL"); CCAssert( dynamic_cast<CCParticleSystem*>(child) != NULL, "CCParticleBatchNode only supports CCQuadParticleSystems as children"); CCAssert( m_pChildren->containsObject(child), "Child doesn't belong to batch" ); CCParticleSystem* pChild = (CCParticleSystem*)(child); if( zOrder == child->getZOrder() ) { return; } // no reordering if only 1 child if( m_pChildren->count() > 1) { unsigned int newIndex = 0, oldIndex = 0; getCurrentIndex(&oldIndex, &newIndex, pChild, zOrder); if( oldIndex != newIndex ) { // reorder m_pChildren->array pChild->retain(); m_pChildren->removeObjectAtIndex(oldIndex); m_pChildren->insertObject(pChild, newIndex); pChild->release(); // save old altasIndex unsigned int oldAtlasIndex = pChild->getAtlasIndex(); // update atlas index updateAllAtlasIndexes(); // Find new AtlasIndex unsigned int newAtlasIndex = 0; for( unsigned int i=0; i < m_pChildren->count(); i++) { CCParticleSystem* pNode = (CCParticleSystem*)m_pChildren->objectAtIndex(i); if( pNode == pChild ) { newAtlasIndex = pChild->getAtlasIndex(); break; } } // reorder textureAtlas quads m_pTextureAtlas->moveQuadsFromIndex(oldAtlasIndex, pChild->getTotalParticles(), newAtlasIndex); pChild->updateWithNoTime(); } } pChild->setZOrder(zOrder); }
bool MainMenuScene::init() { menuLayer = CCLayer::create(); CCSize size = CCDirector::sharedDirector()->getWinSize(); // Add backgrounbdPic CCSprite* backGroundPic = CCSprite::create("pictures/mainMenuBackGround.png"); backGroundPic->setAnchorPoint(ccp(0, 0)); menuLayer->addChild(backGroundPic,0); // Add ChenXiaoG welcome armature CCArmatureDataManager::sharedArmatureDataManager()->addArmatureFileInfo("animations/ChenXiaoGeWelcome.ExportJson"); CCArmature *armature = CCArmature::create("ChenXiaoGeWelcome"); armature->getAnimation()->play("Animation1"); armature->getAnimation()->setSpeedScale(1.5f); armature->setAnchorPoint(ccp(0,0)); armature->setPosition(ccp(size.width/8, size.height/6)); armature->setScale(0.5); menuLayer->addChild(armature,1); //Add StartBtn CCSprite* start = CCSprite::create("pictures/startbtn.png"); CCSprite* startPush = CCSprite::create("pictures/startbtnPush.png"); CCMenuItemSprite * startBtn = CCMenuItemSprite::create(start, startPush, this, menu_selector(MainMenuScene::startBtnCallFunc)); //Add Menu mainMenu = CCMenu::create(startBtn, NULL); mainMenu->setAnchorPoint(ccp(0, 0)); mainMenu->setPosition(ccp(size.width/6, size.height/1.3)); menuLayer->addChild(mainMenu,2); //Add snow particle CCParticleSystem *particle = CCParticleSnow::create(); particle->setTexture(CCTextureCache::sharedTextureCache()->addImage("pictures/snow.png")); menuLayer->addChild(particle,3); this->addChild(menuLayer ,0); return true; }
void TestParticle::initSun() { CCParticleSystem *emitter = CCParticleSun::create(); emitter->retain(); addChild(emitter,10); emitter->setStartSize(20.f); emitter->setSpeed(50.f); emitter->setTexture(CCTextureCache::sharedTextureCache()->addImage("fire.png")); emitter->setPosition(ccp(size.width/6*4,size.height-85)); emitter->release(); }
void TestParticle::initRain() { CCParticleSystem *emitter = CCParticleRain::create(); emitter->retain(); addChild(emitter, 10); CCPoint p = emitter->getPosition(); emitter->setPosition( ccp( p.x, p.y-100) ); emitter->setLife(4); emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage("fire.png") ); emitter->setPosition(ccp(400,50)); emitter->release(); }
void HelloWorld::createParticleEffect(const char* filename, float x, float y, ccColor4F startColor, float duration, float endSize) { CCParticleSystem* emitter = CCParticleSystemQuad::create(filename); emitter->setPosition(x,y); emitter->setStartColor(startColor); emitter->setDuration(duration); emitter->setEndSize(endSize); emitter->setAutoRemoveOnFinish(true); addChild(emitter, 10); }
void TestParticle::initFirework() { CCParticleSystem *emitter = CCParticleFireworks::create(); emitter->retain(); addChild(emitter,10); emitter->setStartSize(20.0f); emitter->setSpeed(150.0f); emitter->setTexture(CCTextureCache::sharedTextureCache()->addImage("stars.png")); //emitter->setDuration(5.0f); emitter->setPosition(ccp(size.width/6*2,size.height-150)); emitter->release(); }
void TestParticle::initSmoke() { CCParticleSystem *emitter = CCParticleSmoke::create(); emitter->retain(); this->addChild(emitter, 10); emitter->setStartSize(20.0f); //emitter->setTotalParticles(300); emitter->setSpeed(150.0f); //设置速度 emitter->setTexture( CCTextureCache::sharedTextureCache()->addImage("fire.png") ); //设置图片 //emitter->setDuration(5.0f); //设置时间 emitter->setPosition(ccp(size.width/6,size.height-150)); //设置初始位置 emitter->release(); }