添加粒子:
void PopStarManager::AddParticlePool()
{
CCLOG("popstar---AddParticlePool----1");
m_ParticleBatchNodeStar =CCParticleBatchNode::create("pop_stars.png");
m_ParticleBatchNodeStar->retain();
if(m_dataGameParticle==NULL)
{
m_dataGameParticle = CCDictionary::create();
m_dataGameParticle->retain();
vector<string> pArray;
pArray.push_back("pop_star1000.plist");
pArray.push_back("pop_star1001.plist");
pArray.push_back("pop_star1002.plist");
pArray.push_back("pop_star1003.plist");
pArray.push_back("pop_star1004.plist");
//CCObject* obj=NULL;
for(int i=0;i<(int)pArray.size();i++)
{
CCParticleSystemQuad* particleSystem = CCParticleSystemQuad::create(pArray[i].c_str());
m_dataGameParticle->setObject(particleSystem,pArray[i]);
}
}
}
播放粒子:
void PopStarManager::ShowParticle( CCPoint _ptOrigin , int _iCate )
{
CCParticleSystemQuad* particle = (CCParticleSystemQuad*)m_dataGameParticle->objectForKey(CCString::createWithFormat("pop_star%d.plist",_iCate)->getCString());
if(particle==NULL) return;
CCParticleSystemQuad* newParticle = CCParticleSystemQuad::create();
newParticle->setAngle(particle->getAngle());
newParticle->setAngleVar(particle->getAngleVar());
newParticle->setBlendFunc(particle->getBlendFunc());//必须放setBlendAdditive上面
newParticle->setBlendAdditive(particle->isBlendAdditive());
newParticle->setDuration(particle->getDuration());
newParticle->setTotalParticles(newParticle->getTotalParticles());
newParticle->setContentSize(particle->getContentSize());
newParticle->setEndColor(particle->getEndColor());
newParticle->setEndColorVar(particle->getEndColorVar());
newParticle->setStartColor(particle->getStartColor());
newParticle->setStartColorVar(particle->getStartColorVar());
newParticle->setStartSize(particle->getStartSize());
newParticle->setStartSizeVar(particle->getStartSizeVar());
newParticle->setEndSize(particle->getEndSize());
newParticle->setEndSizeVar(particle->getEndSizeVar());
newParticle->setPosition(particle->getPosition());
newParticle->setPosVar(particle->getPosVar());
newParticle->setStartSpin(particle->getStartSpin());
newParticle->setStartSpinVar(particle->getStartSpinVar());
newParticle->setEndSpin(particle->getEndSpin());
newParticle->setEndSpinVar(particle->getEndSpinVar());
newParticle->setEmitterMode(particle->getEmitterMode());
if( newParticle->getEmitterMode() == kCCParticleModeGravity )
{
// gravity
newParticle->setGravity(particle->getGravity());
// speed
newParticle->setSpeed(particle->getSpeed());
newParticle->setSpeedVar(particle->getSpeedVar());
// radial acceleration
newParticle->setRadialAccel(particle->getRadialAccel());
newParticle->setRadialAccelVar(particle->getRadialAccelVar());
// tangential acceleration
newParticle->setTangentialAccel(particle->getTangentialAccel());
newParticle->setTangentialAccelVar(particle->getTangentialAccelVar());
// rotation is dir
newParticle->setRotationIsDir(particle->getRotationIsDir());
}
// or Mode B: radius movement
else if( newParticle->getEmitterMode() == kCCParticleModeRadius)
{
newParticle->setStartRadius(particle->getStartRadius());
newParticle->setStartRadiusVar(particle->getStartRadiusVar());
newParticle->setEndRadius(particle->getEndRadius());
newParticle->setEndRadiusVar(particle->getEndRadiusVar());
newParticle->setRotatePerSecond(particle->getRotatePerSecond());
newParticle->setRotatePerSecondVar(particle->getRotatePerSecondVar());
}
newParticle->setLife(particle->getLife());
newParticle->setLifeVar(particle->getLifeVar());
newParticle->setEmissionRate(particle->getEmissionRate());
newParticle->setTexture(particle->getTexture());
newParticle->setAutoRemoveOnFinish(true);
newParticle->setPosition(_ptOrigin);
m_ParticleBatchNodeStar->addChild(newParticle);
}