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; }
// on "init" you need to initialize your instance bool HelloWorld::init() { ////////////////////////////// // 1. super init first if ( !CCLayer::init() ) { return false; } CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin(); ///////////////////////////// // 2. add a menu item with "X" image, which is clicked to quit the program // you may modify it. // add a "close" icon to exit the progress. it's an autorelease object CCMenuItemImage *pCloseItem = CCMenuItemImage::create( "CloseNormal.png", "CloseSelected.png", this, menu_selector(HelloWorld::menuCloseCallback)); pCloseItem->setPosition(ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2 , origin.y + pCloseItem->getContentSize().height/2)); this->addChild(pCloseItem, 10); CCSprite* pSprite = CCSprite::create("IMG1.jpg"); pSprite->setPosition(ccp(-20 + origin.x, origin.y)); pSprite->setAnchorPoint(ccp(0, 0)); this->addChild(pSprite, 0); CCParticleSystem* m_emitter1 = CCParticleSystemQuad::create("snow.plist"); m_emitter1->retain(); CCParticleBatchNode *batch = CCParticleBatchNode::createWithTexture(m_emitter1->getTexture()); batch->addChild(m_emitter1); m_emitter1->setPosition(ccp(240, 700)); addChild(batch, 10); m_emitter1->release(); //addChild(m_emitter1); return true; }