第一種方法:自訂
//建立一個粒子系統 CCParticleSystem* pParticleSystem=new CCParticleSystemQuad(); //產生300個粒子 pParticleSystem->initWithTotalParticles(300); //設定粒子圖片 pParticleSystem->setTexture(CCTextureCache::sharedTextureCache()->addImage("yezi.png")); //設定粒子系統期間 pParticleSystem->setDuration(-1); //設定重力方向 pParticleSystem->setGravity(CCPointZero); //設定角度,角度變動率 pParticleSystem->setAngle(0); pParticleSystem->setAngleVar(360); //設定運動速度,運動速度的變動率 pParticleSystem->setSpeed(50); pParticleSystem->setSpeedVar(10); //設定徑向加速度,徑向加速度的變動率 pParticleSystem->setRadialAccel(70); pParticleSystem->setRadialAccelVar(10); //設定切向加速度,徑向加速度的變動率 pParticleSystem->setTangentialAccel(80); pParticleSystem->setTangentialAccelVar(0); //設定粒子初始位置,位置變動率 pParticleSystem->setPosition(mSize.width/2,mSize.height/2); pParticleSystem->setPosVar(ccp(100,100)); //設定粒子存在時間,時間變動率 pParticleSystem->setLife(2); pParticleSystem->setLifeVar(0.3); //設定粒子初始顏色,顏色變動率 ccColor4F cccStart={0.5,0.5,0.5,1.0}; pParticleSystem->setStartColor(cccStart); pParticleSystem->setStartColorVar(cccStart); //設定粒子結束顏色,顏色變動率 ccColor4F cccEnd={0.5,0.5,0.5,1.0}; pParticleSystem->setStartColor(cccEnd); pParticleSystem->setStartColorVar(cccEnd); //設定粒子初始大小,大小變動率 pParticleSystem->setStartSize(10); pParticleSystem->setStartSizeVar(20); //設定粒子結束大小,大小變動率 pParticleSystem->setStartSize(12); pParticleSystem->setStartSizeVar(12); //設定每秒產生粒子數 pParticleSystem->setEmissionRate(pParticleSystem->getTotalParticles()/pParticleSystem->getLife()); this->addChild(pParticleSystem,1);
效果圖: