Cocos2d-x之Particle System粒子系統

你的遊戲可能需要一些特效,如烈火、 施法視覺效果 、爆炸等等都可以通過particle system(粒子系統)來實現。 粒子系統是指計算機圖形學技術,使用大量非常小的精靈或其他圖形對象來模擬某些模糊現象, 否則很難用傳統的渲染技術再現 。 實際的例子可能包括高度混沌的系統、自然現象或由化學反應引起的過程。

你可以手動創建粒子效果,也有第三方工具可以有助創建,如:

  1. Effekseer:創建粒子效果
  2. Particle Designer:粒子設計
  3. V-play particle editor:跨平臺粒子編輯器
  4. Particle2dx:粒子在線編輯器「推薦」

這些工具通常都會導出一個.plist 文件。 這個文件可以被Cocos2d-x使用:

// create by plist file
auto particleSystem = ParticleSystem::create("SpinningPeas.plist");

內置粒子效果

  • ParticleFire
  • ParticleFireworks
  • ParticleSun
  • ParticleGalaxy
  • ParticleFlower
  • ParticleMeteor
  • ParticleSpiral
  • ParticleExplosion
  • ParticleSmoke
  • ParticleSnow
  • ParticleRain

使用舉例:

auto emitter = ParticleFireworks::create();

addChild(emitter, 10);

我們還可以調整內置粒子效果的屬性:

auto emitter = ParticleFireworks::create();

// set the duration
emitter->setDuration(ParticleSystem::DURATION_INFINITY);

// radius mode
emitter->setEmitterMode(ParticleSystem::Mode::RADIUS);

// radius mode: 100 pixels from center
emitter->setStartRadius(100);
emitter->setStartRadiusVar(0);
emitter->setEndRadius(ParticleSystem::START_RADIUS_EQUAL_TO_END_RADIUS);
emitter->setEndRadiusVar(0);    // not used when start == end

addChild(emitter, 10);
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章