cocos2d-x Particle粒子效果

     我们在写游戏的过程中为了显示爆炸或者碰撞的效果,需要以一定的形式进行表现,这时就可能需要 粒子 效果。例如碰撞时的碎片,子弹的运动过程中可能裹着一团火焰等。
      CCParticleSmoke是类似冒烟的效果,下面看代码:

头文件:MyParticleScence.h
#pragma  once
#ifndef  __MyParticleScence_H__
#define  __MyParticleScence_H__
#include  "cocos2d.h"
using  namespace  cocos2d;
class  MyParticleScence :
      public  CCLayer
{
public :
      static  CCScene* createScene();
     MyParticleScence(  void );
     ~MyParticleScence(  void );
      virtual  bool  init();
     CREATE_FUNC(MyParticleScence);

private :
     CCParticleSystem* particlSystem;
     CCSprite* backgroundSprite;

};

#endif


MyParticleScence.cpp
#include  "MyParticleScence.h"


MyParticleScence::MyParticleScence(  void )
{
}


MyParticleScence::~MyParticleScence(  void )
{
}

CCScene*  MyParticleScence::createScene(){
     CCScene* particleScene = NULL;
      do
     {
           particleScene = CCScene::create();
           CC_BREAK_IF(!particleScene);
           MyParticleScence* myParticleScene = MyParticleScence::create();
           CC_BREAK_IF(!myParticleScene);
           particleScene->addChild(myParticleScene);


     }  while  (0);

      return  particleScene;
}

bool  MyParticleScence::init(){
      bool  bRet =  false ;
      do
     {
           CCSize screenSize = CCDirector::sharedDirector()->getWinSize();
           backgroundSprite = CCSprite::create( "background3.jpg"  );
           CC_BREAK_IF(!backgroundSprite);
           backgroundSprite->setPosition(ccp( screenSize.width/2 , screenSize.height/2 ));
             this ->addChild(backgroundSprite);

             //下?面?的?两?中D效果?都?可以?使1用?
             /*particlSystem = CCParticleFire::create();*/
           particlSystem = CCParticleSmoke::create();
           CC_BREAK_IF(!particlSystem);
           
          particlSystem->setTexture(CCTextureCache::sharedTextureCache()->addImage(  "loading_04.png" ));
             //可以?设置?粒子效果?在精?灵中D的?位?置?
          particlSystem->setPosition(backgroundSprite->getContentSize().width/3,backgroundSprite->getContentSize().height/3);
           

           backgroundSprite->addChild(particlSystem);



           bRet =  true ;

     }  while  (0);
      return  bRet;
}

 
在这里 particlSystem  也可以不显示在CCSprite上,而直接加载Layer上。 loading_04.png就形成一种冒烟的效果,然后不断的屏幕上展示,每一种粒子效果都有一个展示的粒子数或者其他各项参数,这些都体现在它们的封装类中。
一些粒子效果:
  -- CCParticleExplosion       (爆炸粒子效果)  
   -- CCParticleFireworks       (烟花粒子效果)  
   -- CCParticleFire               (火焰粒子效果)  
   -- CCParticleFlower           (花束粒子效果)  
   -- CCParticleGalaxy          (星系粒子效果)  
   -- CCParticleMeteor          (流星粒子效果)  
   -- CCParticleSpiral           (漩涡粒子效果)  
   -- CCParticleSnow            (雪粒子效果)  
   -- CCParticleSmoke          (烟粒子效果)  
   -- CCParticleSun              (太阳粒子效果)  
   -- CCParticleRain             (雨粒子效果)

源代码链接:http://pan.baidu.com/s/1ABrGZ

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值