Cocos2d-x_粒子特效

//
// HelloWorldScene.h
//

#ifndef __HELLOWORLD_SCENE_H__
#define __HELLOWORLD_SCENE_H__

#include "cocos2d.h"
#include "cocos-ext.h"

USING_NS_CC;
USING_NS_CC_EXT;

class HelloWorld : public cocos2d::CCLayer
{
public:
    virtual bool init();
    static cocos2d::CCScene* scene();

    CREATE_FUNC(HelloWorld);

};

#endif

//
// HelloWorldScene.cpp
//

#include "HelloWorldScene.h"
#include "SimpleAudioEngine.h"
#include "BaseData.h"

USING_NS_CC;
using namespace std;
using namespace CocosDenshion;


CCScene* HelloWorld::scene()
{
    CCScene *scene = CCScene::create();
    HelloWorld *layer = HelloWorld::create();
    scene->addChild(layer);
    
    return scene;
}

bool HelloWorld::init()
{
    if ( !CCLayer::init() )
    {
        return false;
    }
    
    CCSize winSize = CCDirector::sharedDirector()->getWinSize();
    
    // 爆炸粒子效果
    CCParticleSystem *particleExplosion = CCParticleExplosion::create();
    particleExplosion->setTexture(CCTextureCache::sharedTextureCache()->addImage("stars.png"));
    
    // 火焰粒子效果
    CCParticleSystem *particleFire = CCParticleFire::create();
    particleFire->setTexture(CCTextureCache::sharedTextureCache()->addImage("fire.png"));
    
    // 花束粒子效果
    CCParticleSystem *particleFlower = CCParticleFlower::create();
    particleFlower->setTexture(CCTextureCache::sharedTextureCache()->addImage("fire.png"));

    // 烟火粒子效果
    CCParticleSystem *particleFireWorks = CCParticleFireworks::create();
    particleFireWorks->setTexture(CCTextureCache::sharedTextureCache()->addImage("fire.png"));
    
    // 星系粒子效果
    CCParticleSystem *particleGalaxy = CCParticleGalaxy::create();
    particleGalaxy->setTexture(CCTextureCache::sharedTextureCache()->addImage("fire.png"));
    
    // 流星粒子效果
    CCParticleSystem *particleMeteor = CCParticleMeteor::create();
    particleMeteor->setTexture(CCTextureCache::sharedTextureCache()->addImage("fire.png"));
    
    // 下雨粒子效果
    CCParticleSystem *particleRain = CCParticleRain::create();
    particleRain->setTexture(CCTextureCache::sharedTextureCache()->addImage("fire.png"));
    
    // 烟雾粒子效果
    CCParticleSystem *particleSmoke = CCParticleSmoke::create();
    particleSmoke->setTexture(CCTextureCache::sharedTextureCache()->addImage("fire.png"));
    
    // 下雪粒子效果
    CCParticleSystem *particleSnow = CCParticleSnow::create();
    particleSnow->setTexture(CCTextureCache::sharedTextureCache()->addImage("snow.png"));
    
    // 漩涡粒子效果
    CCParticleSystem *particleSprial = CCParticleSpiral::create();
    particleSprial->setTexture(CCTextureCache::sharedTextureCache()->addImage("fire.png"));
    
    // 太阳粒子效果
    CCParticleSystem *particleSun = CCParticleSun::create();
    particleSun->setTexture(CCTextureCache::sharedTextureCache()->addImage("fire.png"));
    
    // 系统自带的各种粒子效果展示
    particleSun->setAutoRemoveOnFinish(true);
    particleSun->setPositionType(kCCPositionTypeFree);
    particleSun->setPosition(ccp(winSize.width*0.5,winSize.height*0.5));
    this->addChild(particleSun);
    
    // 观察两种粒子效果
    CCParticleSystem *particleSun1 = CCParticleSun::create();
    particleSun1->setTexture(CCTextureCache::sharedTextureCache()->addImage("fire.png"));
    particleSun1->setAutoRemoveOnFinish(true);
    particleSun1->setPositionType(kCCPositionTypeFree);
    particleSun1->setPosition(ccp(90,160));
    this->addChild(particleSun1);
    
    CCParticleSystem *particleSun2 = CCParticleSun::create();
    particleSun2->setTexture(CCTextureCache::sharedTextureCache()->addImage("fire.png"));
    particleSun2->setAutoRemoveOnFinish(true);
    particleSun2->setPositionType(kCCPositionTypeRelative);
    particleSun2->setPosition(ccp(200,160));
    this->addChild(particleSun2);
    
    CCActionInterval *moveTo = CCMoveBy::create(3,ccp(290,0));
    CCActionInterval *back = moveTo->reverse();
    
    this->runAction(CCSequence::create(moveTo,back,NULL));
    
    /*
     kCCPositionTypeFree,自由模式,粒子在喷射后不再与发射器联系在一起,因此会形成拖尾效果
     kCCPositionTypeRelative,相对模式,粒子发射器会跟随节点移动而移动
     kCCPositionTypeGrouped,与相对模式类似,区别在于此种类型的粒子跟随发射器移动而移动
     */
    return true;
}


bool HelloWorld::init()
{
    if ( !CCLayer::init() )
    {
        return false;
    }
    
    CCSize winSize = CCDirector::sharedDirector()->getWinSize();

    // 自定义粒子效果
    CCParticleSystem *particleSystem = CCParticleSystemQuad::create("cxm.plist");
    this->addChild(particleSystem);
    
    /*
     自定义粒子效果,可以使用粒子编辑器ParticleDesigner,在粒子编辑器中设置好粒子效果,导出plist文件,然后使用CCParticleSystemQuad类即可创建自定义粒子效果
     */
    return true;
}

相关文章

操作步骤 1、创建cocos2d-x工程 2、新建 Scene1.cpp Scene1.h Scene1.h代码 #ifndef __SCENE1_H__#defi...
开发环境:OS(WINDOWS 8.1 X64 企业版) cocos2d-x 2.2.1 vs2010 想给vs安装上cocos的模版,执行Install...
把创建项目做成一个批处理,当创建项目时可以省时省力很多。 操作步骤 1、在 E:cocos2d-x-2.2.1toolspr...
https://www.cnblogs.com/JiaoQing/p/3906780.html 四个响应函数 1 EventListenerPhysicsContact* evC...
转载于 http://www.cnblogs.com/kenkofox/p/3926797.html 熟悉js的dom事件或者flash事件的,基本都能立...
ScrollView(滚动容器)加载大量item时会导致游戏界面的卡顿,严重时整个界面会出现卡死的情况。最近项...