Cocos2d-x_粒子特效

Cocos2d-x_粒子特效,第1张

概述//// 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
//// 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_粒子特效全部内容,希望文章能够帮你解决Cocos2d-x_粒子特效所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1005235.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存