123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236 |
- /****************************************************************************
- Copyright (c) 2008-2010 Ricardo Quesada
- Copyright (c) 2010-2012 cocos2d-x.org
- Copyright (c) 2011 Zynga Inc.
- Copyright (c) 2013-2016 Chukong Technologies Inc.
- Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
-
- http://www.cocos2d-x.org
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
- ****************************************************************************/
- #include "2d/CCParticleExamples.h"
- #include "base/CCDirector.h"
- #include "base/firePngData.h"
- #include "renderer/CCTextureCache.h"
- NS_CC_BEGIN
- //
- // ParticleFire
- //
- static Texture2D* getDefaultTexture()
- {
- Texture2D* texture = nullptr;
- Image* image = nullptr;
- do
- {
- const std::string key = "/__firePngData";
- texture = Director::getInstance()->getTextureCache()->getTextureForKey(key);
- CC_BREAK_IF(texture != nullptr);
- image = new (std::nothrow) Image();
- CC_BREAK_IF(nullptr == image);
- bool ret = image->initWithImageData(__firePngData, sizeof(__firePngData));
- CC_BREAK_IF(!ret);
- texture = Director::getInstance()->getTextureCache()->addImage(image, key);
- } while (0);
- CC_SAFE_RELEASE(image);
- return texture;
- }
- ParticleFire* ParticleFire::create()
- {
- ParticleFire* ret = new (std::nothrow) ParticleFire();
- if (ret && ret->init())
- {
- ret->autorelease();
- }
- else
- {
- CC_SAFE_DELETE(ret);
- }
- return ret;
- }
- ParticleFire* ParticleFire::createWithTotalParticles(int numberOfParticles)
- {
- ParticleFire* ret = new (std::nothrow) ParticleFire();
- if (ret && ret->initWithTotalParticles(numberOfParticles))
- {
- ret->autorelease();
- }
- else
- {
- CC_SAFE_DELETE(ret);
- }
- return ret;
- }
- bool ParticleFire::initWithTotalParticles(int numberOfParticles)
- {
- if( ParticleSystemQuad::initWithTotalParticles(numberOfParticles) )
- {
- // duration
- _duration = DURATION_INFINITY;
- // Gravity Mode
- this->_emitterMode = Mode::GRAVITY;
- // Gravity Mode: gravity
- this->modeA.gravity.setZero();
- // Gravity Mode: radial acceleration
- this->modeA.radialAccel = 0;
- this->modeA.radialAccelVar = 0;
- // Gravity Mode: speed of particles
- this->modeA.speed = 60;
- this->modeA.speedVar = 20;
- // starting angle
- _angle = 90;
- _angleVar = 10;
- // emitter position
- Size winSize = Director::getInstance()->getWinSize();
- this->setPosition(winSize.width/2.0f, 60.0f);
- this->_posVar.set(40.0f, 20.0f);
- // life of particles
- _life = 3;
- _lifeVar = 0.25f;
- // size, in pixels
- _startSize = 54.0f;
- _startSizeVar = 10.0f;
- _endSize = START_SIZE_EQUAL_TO_END_SIZE;
- // emits per frame
- _emissionRate = _totalParticles/_life;
- // color of particles
- _startColor.r = 0.76f;
- _startColor.g = 0.25f;
- _startColor.b = 0.12f;
- _startColor.a = 1.0f;
- _startColorVar.r = 0.0f;
- _startColorVar.g = 0.0f;
- _startColorVar.b = 0.0f;
- _startColorVar.a = 0.0f;
- _endColor.r = 0.0f;
- _endColor.g = 0.0f;
- _endColor.b = 0.0f;
- _endColor.a = 1.0f;
- _endColorVar.r = 0.0f;
- _endColorVar.g = 0.0f;
- _endColorVar.b = 0.0f;
- _endColorVar.a = 0.0f;
- Texture2D* texture = getDefaultTexture();
- if (texture != nullptr)
- {
- setTexture(texture);
- }
-
- // additive
- this->setBlendAdditive(true);
- return true;
- }
- return false;
- }
- //
- // ParticleFireworks
- //
- ParticleFireworks* ParticleFireworks::create()
- {
- ParticleFireworks* ret = new (std::nothrow) ParticleFireworks();
- if (ret && ret->init())
- {
- ret->autorelease();
- }
- else
- {
- CC_SAFE_DELETE(ret);
- }
- return ret;
- }
- ParticleFireworks* ParticleFireworks::createWithTotalParticles(int numberOfParticles)
- {
- ParticleFireworks* ret = new (std::nothrow) ParticleFireworks();
- if (ret && ret->initWithTotalParticles(numberOfParticles))
- {
- ret->autorelease();
- }
- else
- {
- CC_SAFE_DELETE(ret);
- }
- return ret;
- }
- bool ParticleFireworks::initWithTotalParticles(int numberOfParticles)
- {
- if( ParticleSystemQuad::initWithTotalParticles(numberOfParticles) )
- {
- // duration
- _duration= DURATION_INFINITY;
- // Gravity Mode
- this->_emitterMode = Mode::GRAVITY;
- // Gravity Mode: gravity
- this->modeA.gravity.set(0.0f, -90.0f);
- // Gravity Mode: radial
- this->modeA.radialAccel = 0.0f;
- this->modeA.radialAccelVar = 0.0f;
- // Gravity Mode: speed of particles
- this->modeA.speed = 180.0f;
- this->modeA.speedVar = 50.0f;
- // emitter position
- Size winSize = Director::getInstance()->getWinSize();
- this->setPosition(winSize.width/2, winSize.height/2);
- // angle
- this->_angle= 90.0f;
- this->_angleVar = 20.0f;
- // life of particles
- this->_life = 3.5f;
- this->_lifeVar = 1.0f;
- // emits per frame
- this->_emissionRate = _totalParticles/_life;
- // color of particles
- _startColor.r = 0.5f;
- _startColor.g = 0.5f;
- _startColor.b = 0.5f;
- _startColor.a = 1.0f;
- _startColorVar.r = 0.5f;
- _startColorVar.g = 0.5f;
- _startColorVar.b = 0.5f;
- _startColorVar.a = 0.1f;
- _endColor.r = 0.1f;
- _endColor.g = 0.1f;
- _endColor.b = 0.1f;
- _endColor.a = 0.2f;
- _endColorVar.r = 0.1f;
- _endColorVar.g = 0.1f;
- _endColorVar.b = 0.1f;
- _endColorVar.a = 0.2f;
- // size, in pixels
- _startSize = 8.0f;
- _startSizeVar = 2.0f;
- _endSize = START_SIZE_EQUAL_TO_END_SIZE;
- Texture2D* texture = getDefaultTexture();
- if (texture != nullptr)
- {
- setTexture(texture);
- }
- // additive
- this->setBlendAdditive(false);
- return true;
- }
- return false;
- }
- //
- // ParticleSun
- //
- ParticleSun* ParticleSun::create()
- {
- ParticleSun* ret = new (std::nothrow) ParticleSun();
- if (ret && ret->init())
- {
- ret->autorelease();
- }
- else
- {
- CC_SAFE_DELETE(ret);
- }
- return ret;
- }
- ParticleSun* ParticleSun::createWithTotalParticles(int numberOfParticles)
- {
- ParticleSun* ret = new (std::nothrow) ParticleSun();
- if (ret && ret->initWithTotalParticles(numberOfParticles))
- {
- ret->autorelease();
- }
- else
- {
- CC_SAFE_DELETE(ret);
- }
- return ret;
- }
- bool ParticleSun::initWithTotalParticles(int numberOfParticles)
- {
- if( ParticleSystemQuad::initWithTotalParticles(numberOfParticles) )
- {
- // additive
- this->setBlendAdditive(true);
- // duration
- _duration = DURATION_INFINITY;
- // Gravity Mode
- setEmitterMode(Mode::GRAVITY);
- // Gravity Mode: gravity
- setGravity(Vec2(0,0));
- // Gravity mode: radial acceleration
- setRadialAccel(0);
- setRadialAccelVar(0);
- // Gravity mode: speed of particles
- setSpeed(20);
- setSpeedVar(5);
- // angle
- _angle = 90;
- _angleVar = 360;
- // emitter position
- Size winSize = Director::getInstance()->getWinSize();
- this->setPosition(winSize.width/2, winSize.height/2);
- setPosVar(Vec2::ZERO);
- // life of particles
- _life = 1;
- _lifeVar = 0.5f;
- // size, in pixels
- _startSize = 30.0f;
- _startSizeVar = 10.0f;
- _endSize = START_SIZE_EQUAL_TO_END_SIZE;
- // emits per seconds
- _emissionRate = _totalParticles/_life;
- // color of particles
- _startColor.r = 0.76f;
- _startColor.g = 0.25f;
- _startColor.b = 0.12f;
- _startColor.a = 1.0f;
- _startColorVar.r = 0.0f;
- _startColorVar.g = 0.0f;
- _startColorVar.b = 0.0f;
- _startColorVar.a = 0.0f;
- _endColor.r = 0.0f;
- _endColor.g = 0.0f;
- _endColor.b = 0.0f;
- _endColor.a = 1.0f;
- _endColorVar.r = 0.0f;
- _endColorVar.g = 0.0f;
- _endColorVar.b = 0.0f;
- _endColorVar.a = 0.0f;
- Texture2D* texture = getDefaultTexture();
- if (texture != nullptr)
- {
- setTexture(texture);
- }
- return true;
- }
- return false;
- }
- //
- // ParticleGalaxy
- //
- ParticleGalaxy* ParticleGalaxy::create()
- {
- ParticleGalaxy* ret = new (std::nothrow) ParticleGalaxy();
- if (ret && ret->init())
- {
- ret->autorelease();
- }
- else
- {
- CC_SAFE_DELETE(ret);
- }
- return ret;
- }
- ParticleGalaxy* ParticleGalaxy::createWithTotalParticles(int numberOfParticles)
- {
- ParticleGalaxy* ret = new (std::nothrow) ParticleGalaxy();
- if (ret && ret->initWithTotalParticles(numberOfParticles))
- {
- ret->autorelease();
- }
- else
- {
- CC_SAFE_DELETE(ret);
- }
- return ret;
- }
- bool ParticleGalaxy::initWithTotalParticles(int numberOfParticles)
- {
- if( ParticleSystemQuad::initWithTotalParticles(numberOfParticles) )
- {
- // duration
- _duration = DURATION_INFINITY;
- // Gravity Mode
- setEmitterMode(Mode::GRAVITY);
- // Gravity Mode: gravity
- setGravity(Vec2(0,0));
- // Gravity Mode: speed of particles
- setSpeed(60);
- setSpeedVar(10);
- // Gravity Mode: radial
- setRadialAccel(-80);
- setRadialAccelVar(0);
- // Gravity Mode: tangential
- setTangentialAccel(80);
- setTangentialAccelVar(0);
- // angle
- _angle = 90;
- _angleVar = 360;
- // emitter position
- Size winSize = Director::getInstance()->getWinSize();
- this->setPosition(winSize.width/2, winSize.height/2);
- setPosVar(Vec2::ZERO);
- // life of particles
- _life = 4;
- _lifeVar = 1;
- // size, in pixels
- _startSize = 37.0f;
- _startSizeVar = 10.0f;
- _endSize = START_SIZE_EQUAL_TO_END_SIZE;
- // emits per second
- _emissionRate = _totalParticles/_life;
- // color of particles
- _startColor.r = 0.12f;
- _startColor.g = 0.25f;
- _startColor.b = 0.76f;
- _startColor.a = 1.0f;
- _startColorVar.r = 0.0f;
- _startColorVar.g = 0.0f;
- _startColorVar.b = 0.0f;
- _startColorVar.a = 0.0f;
- _endColor.r = 0.0f;
- _endColor.g = 0.0f;
- _endColor.b = 0.0f;
- _endColor.a = 1.0f;
- _endColorVar.r = 0.0f;
- _endColorVar.g = 0.0f;
- _endColorVar.b = 0.0f;
- _endColorVar.a = 0.0f;
- Texture2D* texture = getDefaultTexture();
- if (texture != nullptr)
- {
- setTexture(texture);
- }
- // additive
- this->setBlendAdditive(true);
- return true;
- }
- return false;
- }
- //
- // ParticleFlower
- //
- ParticleFlower* ParticleFlower::create()
- {
- ParticleFlower* ret = new (std::nothrow) ParticleFlower();
- if (ret && ret->init())
- {
- ret->autorelease();
- }
- else
- {
- CC_SAFE_DELETE(ret);
- }
- return ret;
- }
- ParticleFlower* ParticleFlower::createWithTotalParticles(int numberOfParticles)
- {
- ParticleFlower* ret = new (std::nothrow) ParticleFlower();
- if (ret && ret->initWithTotalParticles(numberOfParticles))
- {
- ret->autorelease();
- }
- else
- {
- CC_SAFE_DELETE(ret);
- }
- return ret;
- }
- bool ParticleFlower::initWithTotalParticles(int numberOfParticles)
- {
- if( ParticleSystemQuad::initWithTotalParticles(numberOfParticles) )
- {
- // duration
- _duration = DURATION_INFINITY;
- // Gravity Mode
- setEmitterMode(Mode::GRAVITY);
- // Gravity Mode: gravity
- setGravity(Vec2(0,0));
- // Gravity Mode: speed of particles
- setSpeed(80);
- setSpeedVar(10);
- // Gravity Mode: radial
- setRadialAccel(-60);
- setRadialAccelVar(0);
- // Gravity Mode: tangential
- setTangentialAccel(15);
- setTangentialAccelVar(0);
- // angle
- _angle = 90;
- _angleVar = 360;
- // emitter position
- Size winSize = Director::getInstance()->getWinSize();
- this->setPosition(winSize.width/2, winSize.height/2);
- setPosVar(Vec2::ZERO);
- // life of particles
- _life = 4;
- _lifeVar = 1;
- // size, in pixels
- _startSize = 30.0f;
- _startSizeVar = 10.0f;
- _endSize = START_SIZE_EQUAL_TO_END_SIZE;
- // emits per second
- _emissionRate = _totalParticles/_life;
- // color of particles
- _startColor.r = 0.50f;
- _startColor.g = 0.50f;
- _startColor.b = 0.50f;
- _startColor.a = 1.0f;
- _startColorVar.r = 0.5f;
- _startColorVar.g = 0.5f;
- _startColorVar.b = 0.5f;
- _startColorVar.a = 0.5f;
- _endColor.r = 0.0f;
- _endColor.g = 0.0f;
- _endColor.b = 0.0f;
- _endColor.a = 1.0f;
- _endColorVar.r = 0.0f;
- _endColorVar.g = 0.0f;
- _endColorVar.b = 0.0f;
- _endColorVar.a = 0.0f;
- Texture2D* texture = getDefaultTexture();
- if (texture != nullptr)
- {
- setTexture(texture);
- }
- // additive
- this->setBlendAdditive(true);
- return true;
- }
- return false;
- }
- //
- // ParticleMeteor
- //
- ParticleMeteor * ParticleMeteor::create()
- {
- ParticleMeteor *ret = new (std::nothrow) ParticleMeteor();
- if (ret && ret->init())
- {
- ret->autorelease();
- }
- else
- {
- CC_SAFE_DELETE(ret);
- }
- return ret;
- }
- ParticleMeteor* ParticleMeteor::createWithTotalParticles(int numberOfParticles)
- {
- ParticleMeteor* ret = new (std::nothrow) ParticleMeteor();
- if (ret && ret->initWithTotalParticles(numberOfParticles))
- {
- ret->autorelease();
- }
- else
- {
- CC_SAFE_DELETE(ret);
- }
- return ret;
- }
- bool ParticleMeteor::initWithTotalParticles(int numberOfParticles)
- {
- if( ParticleSystemQuad::initWithTotalParticles(numberOfParticles) )
- {
- // duration
- _duration = DURATION_INFINITY;
- // Gravity Mode
- setEmitterMode(Mode::GRAVITY);
- // Gravity Mode: gravity
- setGravity(Vec2(-200,200));
- // Gravity Mode: speed of particles
- setSpeed(15);
- setSpeedVar(5);
- // Gravity Mode: radial
- setRadialAccel(0);
- setRadialAccelVar(0);
- // Gravity Mode: tangential
- setTangentialAccel(0);
- setTangentialAccelVar(0);
- // angle
- _angle = 90;
- _angleVar = 360;
- // emitter position
- Size winSize = Director::getInstance()->getWinSize();
- this->setPosition(winSize.width/2, winSize.height/2);
- setPosVar(Vec2::ZERO);
- // life of particles
- _life = 2;
- _lifeVar = 1;
- // size, in pixels
- _startSize = 60.0f;
- _startSizeVar = 10.0f;
- _endSize = START_SIZE_EQUAL_TO_END_SIZE;
- // emits per second
- _emissionRate = _totalParticles/_life;
- // color of particles
- _startColor.r = 0.2f;
- _startColor.g = 0.4f;
- _startColor.b = 0.7f;
- _startColor.a = 1.0f;
- _startColorVar.r = 0.0f;
- _startColorVar.g = 0.0f;
- _startColorVar.b = 0.2f;
- _startColorVar.a = 0.1f;
- _endColor.r = 0.0f;
- _endColor.g = 0.0f;
- _endColor.b = 0.0f;
- _endColor.a = 1.0f;
- _endColorVar.r = 0.0f;
- _endColorVar.g = 0.0f;
- _endColorVar.b = 0.0f;
- _endColorVar.a = 0.0f;
- Texture2D* texture = getDefaultTexture();
- if (texture != nullptr)
- {
- setTexture(texture);
- }
- // additive
- this->setBlendAdditive(true);
- return true;
- }
- return false;
- }
- //
- // ParticleSpiral
- //
- ParticleSpiral* ParticleSpiral::create()
- {
- ParticleSpiral* ret = new (std::nothrow) ParticleSpiral();
- if (ret && ret->init())
- {
- ret->autorelease();
- }
- else
- {
- CC_SAFE_DELETE(ret);
- }
- return ret;
- }
- ParticleSpiral* ParticleSpiral::createWithTotalParticles(int numberOfParticles)
- {
- ParticleSpiral* ret = new (std::nothrow) ParticleSpiral();
- if (ret && ret->initWithTotalParticles(numberOfParticles))
- {
- ret->autorelease();
- }
- else
- {
- CC_SAFE_DELETE(ret);
- }
- return ret;
- }
- bool ParticleSpiral::initWithTotalParticles(int numberOfParticles)
- {
- if( ParticleSystemQuad::initWithTotalParticles(numberOfParticles) )
- {
- // duration
- _duration = DURATION_INFINITY;
- // Gravity Mode
- setEmitterMode(Mode::GRAVITY);
- // Gravity Mode: gravity
- setGravity(Vec2(0,0));
- // Gravity Mode: speed of particles
- setSpeed(150);
- setSpeedVar(0);
- // Gravity Mode: radial
- setRadialAccel(-380);
- setRadialAccelVar(0);
- // Gravity Mode: tangential
- setTangentialAccel(45);
- setTangentialAccelVar(0);
- // angle
- _angle = 90;
- _angleVar = 0;
- // emitter position
- Size winSize = Director::getInstance()->getWinSize();
- this->setPosition(winSize.width/2, winSize.height/2);
- setPosVar(Vec2::ZERO);
- // life of particles
- _life = 12;
- _lifeVar = 0;
- // size, in pixels
- _startSize = 20.0f;
- _startSizeVar = 0.0f;
- _endSize = START_SIZE_EQUAL_TO_END_SIZE;
- // emits per second
- _emissionRate = _totalParticles/_life;
- // color of particles
- _startColor.r = 0.5f;
- _startColor.g = 0.5f;
- _startColor.b = 0.5f;
- _startColor.a = 1.0f;
- _startColorVar.r = 0.5f;
- _startColorVar.g = 0.5f;
- _startColorVar.b = 0.5f;
- _startColorVar.a = 0.0f;
- _endColor.r = 0.5f;
- _endColor.g = 0.5f;
- _endColor.b = 0.5f;
- _endColor.a = 1.0f;
- _endColorVar.r = 0.5f;
- _endColorVar.g = 0.5f;
- _endColorVar.b = 0.5f;
- _endColorVar.a = 0.0f;
- Texture2D* texture = getDefaultTexture();
- if (texture != nullptr)
- {
- setTexture(texture);
- }
- // additive
- this->setBlendAdditive(false);
- return true;
- }
- return false;
- }
- //
- // ParticleExplosion
- //
- ParticleExplosion* ParticleExplosion::create()
- {
- ParticleExplosion* ret = new (std::nothrow) ParticleExplosion();
- if (ret && ret->init())
- {
- ret->autorelease();
- }
- else
- {
- CC_SAFE_DELETE(ret);
- }
- return ret;
- }
- ParticleExplosion* ParticleExplosion::createWithTotalParticles(int numberOfParticles)
- {
- ParticleExplosion* ret = new (std::nothrow) ParticleExplosion();
- if (ret && ret->initWithTotalParticles(numberOfParticles))
- {
- ret->autorelease();
- }
- else
- {
- CC_SAFE_DELETE(ret);
- }
- return ret;
- }
- bool ParticleExplosion::initWithTotalParticles(int numberOfParticles)
- {
- if( ParticleSystemQuad::initWithTotalParticles(numberOfParticles) )
- {
- // duration
- _duration = 0.1f;
- setEmitterMode(Mode::GRAVITY);
- // Gravity Mode: gravity
- setGravity(Vec2(0,0));
- // Gravity Mode: speed of particles
- setSpeed(70);
- setSpeedVar(40);
- // Gravity Mode: radial
- setRadialAccel(0);
- setRadialAccelVar(0);
- // Gravity Mode: tangential
- setTangentialAccel(0);
- setTangentialAccelVar(0);
- // angle
- _angle = 90;
- _angleVar = 360;
- // emitter position
- Size winSize = Director::getInstance()->getWinSize();
- this->setPosition(winSize.width/2, winSize.height/2);
- setPosVar(Vec2::ZERO);
- // life of particles
- _life = 5.0f;
- _lifeVar = 2;
- // size, in pixels
- _startSize = 15.0f;
- _startSizeVar = 10.0f;
- _endSize = START_SIZE_EQUAL_TO_END_SIZE;
- // emits per second
- _emissionRate = _totalParticles/_duration;
- // color of particles
- _startColor.r = 0.7f;
- _startColor.g = 0.1f;
- _startColor.b = 0.2f;
- _startColor.a = 1.0f;
- _startColorVar.r = 0.5f;
- _startColorVar.g = 0.5f;
- _startColorVar.b = 0.5f;
- _startColorVar.a = 0.0f;
- _endColor.r = 0.5f;
- _endColor.g = 0.5f;
- _endColor.b = 0.5f;
- _endColor.a = 0.0f;
- _endColorVar.r = 0.5f;
- _endColorVar.g = 0.5f;
- _endColorVar.b = 0.5f;
- _endColorVar.a = 0.0f;
- Texture2D* texture = getDefaultTexture();
- if (texture != nullptr)
- {
- setTexture(texture);
- }
- // additive
- this->setBlendAdditive(false);
- return true;
- }
- return false;
- }
- //
- // ParticleSmoke
- //
- ParticleSmoke* ParticleSmoke::create()
- {
- ParticleSmoke* ret = new (std::nothrow) ParticleSmoke();
- if (ret && ret->init())
- {
- ret->autorelease();
- }
- else
- {
- CC_SAFE_DELETE(ret);
- }
- return ret;
- }
- ParticleSmoke* ParticleSmoke::createWithTotalParticles(int numberOfParticles)
- {
- ParticleSmoke* ret = new (std::nothrow) ParticleSmoke();
- if (ret && ret->initWithTotalParticles(numberOfParticles))
- {
- ret->autorelease();
- }
- else
- {
- CC_SAFE_DELETE(ret);
- }
- return ret;
- }
- bool ParticleSmoke::initWithTotalParticles(int numberOfParticles)
- {
- if( ParticleSystemQuad::initWithTotalParticles(numberOfParticles) )
- {
- // duration
- _duration = DURATION_INFINITY;
- // Emitter mode: Gravity Mode
- setEmitterMode(Mode::GRAVITY);
- // Gravity Mode: gravity
- setGravity(Vec2(0,0));
- // Gravity Mode: radial acceleration
- setRadialAccel(0);
- setRadialAccelVar(0);
- // Gravity Mode: speed of particles
- setSpeed(25);
- setSpeedVar(10);
- // angle
- _angle = 90;
- _angleVar = 5;
- // emitter position
- Size winSize = Director::getInstance()->getWinSize();
- this->setPosition(winSize.width/2, 0);
- setPosVar(Vec2(20, 0));
- // life of particles
- _life = 4;
- _lifeVar = 1;
- // size, in pixels
- _startSize = 60.0f;
- _startSizeVar = 10.0f;
- _endSize = START_SIZE_EQUAL_TO_END_SIZE;
- // emits per frame
- _emissionRate = _totalParticles/_life;
- // color of particles
- _startColor.r = 0.8f;
- _startColor.g = 0.8f;
- _startColor.b = 0.8f;
- _startColor.a = 1.0f;
- _startColorVar.r = 0.02f;
- _startColorVar.g = 0.02f;
- _startColorVar.b = 0.02f;
- _startColorVar.a = 0.0f;
- _endColor.r = 0.0f;
- _endColor.g = 0.0f;
- _endColor.b = 0.0f;
- _endColor.a = 1.0f;
- _endColorVar.r = 0.0f;
- _endColorVar.g = 0.0f;
- _endColorVar.b = 0.0f;
- _endColorVar.a = 0.0f;
- Texture2D* texture = getDefaultTexture();
- if (texture != nullptr)
- {
- setTexture(texture);
- }
- // additive
- this->setBlendAdditive(false);
- return true;
- }
- return false;
- }
- //
- // ParticleSnow
- //
- ParticleSnow* ParticleSnow::create()
- {
- ParticleSnow* ret = new (std::nothrow) ParticleSnow();
- if (ret && ret->init())
- {
- ret->autorelease();
- }
- else
- {
- CC_SAFE_DELETE(ret);
- }
- return ret;
- }
- ParticleSnow* ParticleSnow::createWithTotalParticles(int numberOfParticles)
- {
- ParticleSnow* ret = new (std::nothrow) ParticleSnow();
- if (ret && ret->initWithTotalParticles(numberOfParticles))
- {
- ret->autorelease();
- }
- else
- {
- CC_SAFE_DELETE(ret);
- }
- return ret;
- }
- bool ParticleSnow::initWithTotalParticles(int numberOfParticles)
- {
- if( ParticleSystemQuad::initWithTotalParticles(numberOfParticles) )
- {
- // duration
- _duration = DURATION_INFINITY;
- // set gravity mode.
- setEmitterMode(Mode::GRAVITY);
- // Gravity Mode: gravity
- setGravity(Vec2(0,-1));
- // Gravity Mode: speed of particles
- setSpeed(5);
- setSpeedVar(1);
- // Gravity Mode: radial
- setRadialAccel(0);
- setRadialAccelVar(1);
- // Gravity mode: tangential
- setTangentialAccel(0);
- setTangentialAccelVar(1);
- // emitter position
- Size winSize = Director::getInstance()->getWinSize();
- this->setPosition(winSize.width/2, winSize.height + 10);
- setPosVar(Vec2(winSize.width/2, 0));
- // angle
- _angle = -90;
- _angleVar = 5;
- // life of particles
- _life = 45;
- _lifeVar = 15;
- // size, in pixels
- _startSize = 10.0f;
- _startSizeVar = 5.0f;
- _endSize = START_SIZE_EQUAL_TO_END_SIZE;
- // emits per second
- _emissionRate = 10;
- // color of particles
- _startColor.r = 1.0f;
- _startColor.g = 1.0f;
- _startColor.b = 1.0f;
- _startColor.a = 1.0f;
- _startColorVar.r = 0.0f;
- _startColorVar.g = 0.0f;
- _startColorVar.b = 0.0f;
- _startColorVar.a = 0.0f;
- _endColor.r = 1.0f;
- _endColor.g = 1.0f;
- _endColor.b = 1.0f;
- _endColor.a = 0.0f;
- _endColorVar.r = 0.0f;
- _endColorVar.g = 0.0f;
- _endColorVar.b = 0.0f;
- _endColorVar.a = 0.0f;
- Texture2D* texture = getDefaultTexture();
- if (texture != nullptr)
- {
- setTexture(texture);
- }
- // additive
- this->setBlendAdditive(false);
- return true;
- }
- return false;
- }
- //
- // ParticleRain
- //
- ParticleRain* ParticleRain::create()
- {
- ParticleRain* ret = new (std::nothrow) ParticleRain();
- if (ret && ret->init())
- {
- ret->autorelease();
- }
- else
- {
- CC_SAFE_DELETE(ret);
- }
- return ret;
- }
- ParticleRain* ParticleRain::createWithTotalParticles(int numberOfParticles)
- {
- ParticleRain* ret = new (std::nothrow) ParticleRain();
- if (ret && ret->initWithTotalParticles(numberOfParticles))
- {
- ret->autorelease();
- }
- else
- {
- CC_SAFE_DELETE(ret);
- }
- return ret;
- }
- bool ParticleRain::initWithTotalParticles(int numberOfParticles)
- {
- if( ParticleSystemQuad::initWithTotalParticles(numberOfParticles) )
- {
- // duration
- _duration = DURATION_INFINITY;
- setEmitterMode(Mode::GRAVITY);
- // Gravity Mode: gravity
- setGravity(Vec2(10,-10));
- // Gravity Mode: radial
- setRadialAccel(0);
- setRadialAccelVar(1);
- // Gravity Mode: tangential
- setTangentialAccel(0);
- setTangentialAccelVar(1);
- // Gravity Mode: speed of particles
- setSpeed(130);
- setSpeedVar(30);
- // angle
- _angle = -90;
- _angleVar = 5;
- // emitter position
- Size winSize = Director::getInstance()->getWinSize();
- this->setPosition(winSize.width/2, winSize.height);
- setPosVar(Vec2(winSize.width/2, 0));
- // life of particles
- _life = 4.5f;
- _lifeVar = 0;
- // size, in pixels
- _startSize = 4.0f;
- _startSizeVar = 2.0f;
- _endSize = START_SIZE_EQUAL_TO_END_SIZE;
- // emits per second
- _emissionRate = 20;
- // color of particles
- _startColor.r = 0.7f;
- _startColor.g = 0.8f;
- _startColor.b = 1.0f;
- _startColor.a = 1.0f;
- _startColorVar.r = 0.0f;
- _startColorVar.g = 0.0f;
- _startColorVar.b = 0.0f;
- _startColorVar.a = 0.0f;
- _endColor.r = 0.7f;
- _endColor.g = 0.8f;
- _endColor.b = 1.0f;
- _endColor.a = 0.5f;
- _endColorVar.r = 0.0f;
- _endColorVar.g = 0.0f;
- _endColorVar.b = 0.0f;
- _endColorVar.a = 0.0f;
- Texture2D* texture = getDefaultTexture();
- if (texture != nullptr)
- {
- setTexture(texture);
- }
- // additive
- this->setBlendAdditive(false);
- return true;
- }
- return false;
- }
- NS_CC_END
|