@H_301_1@一、简介
在大自然中,随处可见一些大规模运动的物体,例如下雨时的雨点、下雪时的雪花、爆炸时的火花,甚至旋转的星系、扩散的云雾等。当我们希望在游戏中模拟这些大规模运动的物体时,通常有如下两种方法。
Cocos2d - x中粒子系统由CCParticleSystem类实现,CCParticleSystem实现了对粒子的控制与调度。
@H_301_1@对粒子的操作包括:
产生粒子:也称作粒子发射器。
更新粒子状态:引擎会随时更新粒子的位置、速度及其他状态。
回收无效粒子:当粒子生存周期结束后,被系统回收。
@H_301_1@二、内置粒子系统
Cocos2d-x内置11种粒子效果,其类派生关系如下:
setTexture():设置特效贴图。
setAutoRemoveOnFinish(bool):设置自动释放true为自动释放。
@H_301_1@(一)爆炸效果:CCParticleExplosion
@H_301_1@实例;
CCParticleExplosion * explosion = CCParticleExplosion::create(); explosion->setTexture(CCTextureCache::sharedTextureCache()->addImage("huangjinpao.png")); explosion->setPosition(ccp(200,200)); addChild(explosion);@H_301_1@(二)火焰效果:CCParticleFire
@H_301_1@实例:
CCParticleFire * fire = CCParticleFire::create(); fire->setTexture(CCTextureCache::sharedTextureCache()->addImage("huangjinpao.png")); fire->setPosition(ccp(200,200)); addChild(fire);@H_301_1@(三)花束效果:CCParticleFlower
@H_301_1@实例:
CCParticleFlower* flower = CCParticleFlower::create(); flower->setTexture(CCTextureCache::sharedTextureCache()->addImage("huangjinpao.png")); flower->setPosition(ccp(200,200)); addChild(flower);
@H_301_1@(四)烟花效果:CCParticleFireworks
@H_301_1@实例:
CCParticleFireworks* fireworks = CCParticleFireworks::create(); fireworks->setTexture(CCTextureCache::sharedTextureCache()->addImage("huangjinpao.png")); fireworks->setPosition(ccp(200,200)); addChild(fireworks);
@H_301_1@(五)星系效果:CCParticleGalaxy
@H_301_1@实例:
CCParticleGalaxy* galaxy = CCParticleGalaxy::create(); galaxy->setTexture(CCTextureCache::sharedTextureCache()->addImage("huangjinpao.png")); galaxy->setPosition(ccp(200,200)); addChild(galaxy);@H_301_1@(六)流星效果:CCParticleMeteor
@H_301_1@实例:
CCParticleMeteor* meteor = CCParticleMeteor::create(); meteor->setTexture(CCTextureCache::sharedTextureCache()->addImage("huangjinpao.png")); meteor->setPosition(ccp(200,200)); addChild(meteor);@H_301_1@(七)下雨效果:CCParticleRain
@H_301_1@实例:
CCParticleRain* rain = CCParticleRain::create(); rain->setTexture(CCTextureCache::sharedTextureCache()->addImage("huangjinpao.png")); rain->setPosition(ccp(200,200)); addChild(rain);@H_301_1@(八)烟雾效果:CCParticleSmoke
@H_301_1@实例:
CCParticleSmoke* smoke = CCParticleSmoke::create(); smoke->setTexture(CCTextureCache::sharedTextureCache()->addImage("huangjinpao.png")); smoke->setPosition(ccp(200,200)); addChild(smoke);@H_301_1@(九)下雪效果:CCParticleSnow
@H_301_1@实例:
CCParticleSnow* snow = CCParticleSnow::create(); snow->setTexture(CCTextureCache::sharedTextureCache()->addImage("huangjinpao.png")); snow->setPosition(ccp(200,200)); addChild(snow);@H_301_1@(十)漩涡效果:CCParticleSpiral
@H_301_1@实例:
CCParticleSpiral* spiral = CCParticleSpiral::create(); spiral->setTexture(CCTextureCache::sharedTextureCache()->addImage("huangjinpao.png")); spiral->setPosition(ccp(200,200)); addChild(spiral);@H_301_1@(十一)太阳效果:CCParticleSun
@H_301_1@实例:
CCParticleSun* sun = CCParticleSun::create(); sun->setTexture(CCTextureCache::sharedTextureCache()->addImage("huangjinpao.png")); sun->setPosition(ccp(200,200)); addChild(sun);@H_301_1@三、使用粒子编辑器编辑的粒子效果
@H_301_1@实例:
CCParticleSystemQuad *snow = new CCParticleSystemQuad(); snow->initWithFile("gas_explode.plist"); snow->setPosition(ccp(200,200)); addChild(snow);plist文件可以通过例子编辑器获得。