Cocos2d-x_粒子特效

前端之家收集整理的这篇文章主要介绍了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;
}

猜你在找的Cocos2d-x相关文章