第十一章粒子系统

来源:互联网 发布:花椒直播mac版 编辑:程序博客网 时间:2024/06/05 02:49

Cocos2d-x学习笔记


粒子系统基本概念

“粒子系统”是模拟自然界中的一些粒子的物理运动的效果。单个粒子或几个粒子无法体现出粒子运动的规律性,必须有大量的粒子才体现运行的规律,而且,大量的粒子不断消失,又有大量的粒子不断产生。微观上,粒子运动是随机的,宏观上粒子运动是由规律的,符合物理学中的“测不准原理”。

实例:打火机

bool HelloWorld::init(){    if(!Layer::Init())    {        return false;    }    Size visibleSize = Director::getInstance()->getVisibleSIze();    auto bg = Sprite::create("zippo.png");    bg->setPosition(Vec2(visibleSIze.width/2, visibleSIze.height/2));    this->addChild(bg);    ParticleSystem * particleSystem = ParticleFire::create();//创建火焰粒子系统对象    particleSystem->setPosition(Director::geInstance()->convertTbGL(Vec2(270,380)));//设置粒子系统的位置    this->addChild(particleSystem);//添加火焰粒子系统对象到当前层    return true;}

粒子系统类图:

粒子发射模式

粒子系统发射时有两种模式:重力模式和半径模式。重力模式是让粒子围绕一个中心点做远离或紧接运动,半径模式是让粒子围绕中心点旋转。

内置粒子系统

  • ParticleExplosion:爆炸粒子效果,属于半径模式。
  • ParticleFire:火焰粒子效果,属于重力模式。
  • ParticleFireworks:烟花粒子效果,属于重力模式。
  • ParticleFlower:花粒子效果,属于半径模式。
  • ParticleGalaxy:星系粒子效果,属于半径模式。
  • ParticleMeteor:流星粒子效果,属于重力模式。
  • ParticleSpiral:旋涡粒子效果,属于半径模式。
  • ParticleSnow:雪粒子效果,属于重力模式。
  • ParticleSmoke:烟粒子效果,属于重力模式。
  • ParticleSun:太阳粒子效果,属于重力模式。
  • ParticleRain:雨粒子效果,属于重力模式。

这11种粒子系统每一个都有如下两个create函数,通过create函数可以创建粒子对象。
static ParticleExplosion * create()
static ParticleExplosion * createWithTotalParticles ( int numberOfParticles )
其中,numberOfParticles是粒子初始化的个数。

0 0