axmol/core/2d/ParticleExamples.cpp

1234 lines
29 KiB
C++
Raw Normal View History

2019-11-23 20:27:39 +08:00
/****************************************************************************
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.
2021-12-25 10:04:45 +08:00
https://axmol.dev/
2019-11-23 20:27:39 +08:00
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/ParticleExamples.h"
#include "base/Director.h"
2019-11-23 20:27:39 +08:00
#include "base/firePngData.h"
#include "renderer/TextureCache.h"
2019-11-23 20:27:39 +08:00
namespace ax
{
2019-11-23 20:27:39 +08:00
//
// ParticleFire
//
static Texture2D* getDefaultTexture()
{
Texture2D* texture = nullptr;
2021-12-25 10:04:45 +08:00
Image* image = nullptr;
do
2019-11-23 20:27:39 +08:00
{
const std::string key = "/__firePngData";
2021-12-25 10:04:45 +08:00
texture = Director::getInstance()->getTextureCache()->getTextureForKey(key);
2022-07-16 10:43:05 +08:00
AX_BREAK_IF(texture != nullptr);
2019-11-23 20:27:39 +08:00
2021-12-25 10:04:45 +08:00
image = new Image();
2021-05-24 13:26:56 +08:00
bool ret = image->initWithImageData(__firePngData, sizeof(__firePngData));
2022-07-16 10:43:05 +08:00
AX_BREAK_IF(!ret);
2019-11-23 20:27:39 +08:00
texture = Director::getInstance()->getTextureCache()->addImage(image, key);
} while (0);
2022-07-16 10:43:05 +08:00
AX_SAFE_RELEASE(image);
2019-11-23 20:27:39 +08:00
return texture;
}
ParticleFire* ParticleFire::create()
{
2021-12-08 00:11:53 +08:00
ParticleFire* ret = new ParticleFire();
if (ret->init())
2019-11-23 20:27:39 +08:00
{
ret->autorelease();
}
else
{
2022-07-16 10:43:05 +08:00
AX_SAFE_DELETE(ret);
2019-11-23 20:27:39 +08:00
}
return ret;
}
ParticleFire* ParticleFire::createWithTotalParticles(int numberOfParticles)
{
2021-12-08 00:11:53 +08:00
ParticleFire* ret = new ParticleFire();
if (ret->initWithTotalParticles(numberOfParticles))
2019-11-23 20:27:39 +08:00
{
ret->autorelease();
}
else
{
2022-07-16 10:43:05 +08:00
AX_SAFE_DELETE(ret);
2019-11-23 20:27:39 +08:00
}
return ret;
}
bool ParticleFire::initWithTotalParticles(int numberOfParticles)
{
2021-12-25 10:04:45 +08:00
if (ParticleSystemQuad::initWithTotalParticles(numberOfParticles))
2019-11-23 20:27:39 +08:00
{
// duration
_duration = DURATION_INFINITY;
// Gravity Mode
this->_emitterMode = Mode::GRAVITY;
// Gravity Mode: gravity
this->modeA.gravity.setZero();
// Gravity Mode: radial acceleration
2021-12-25 10:04:45 +08:00
this->modeA.radialAccel = 0;
2019-11-23 20:27:39 +08:00
this->modeA.radialAccelVar = 0;
// Gravity Mode: speed of particles
2021-12-25 10:04:45 +08:00
this->modeA.speed = 60;
this->modeA.speedVar = 20;
2019-11-23 20:27:39 +08:00
// starting angle
2021-12-25 10:04:45 +08:00
_angle = 90;
2019-11-23 20:27:39 +08:00
_angleVar = 10;
// emitter position
2021-10-23 23:27:14 +08:00
Vec2 winSize = _director->getWinSize();
2021-12-25 10:04:45 +08:00
this->setPosition(winSize.width / 2.0f, 60.0f);
2019-11-23 20:27:39 +08:00
this->_posVar.set(40.0f, 20.0f);
// life of particles
2021-12-25 10:04:45 +08:00
_life = 3;
2019-11-23 20:27:39 +08:00
_lifeVar = 0.25f;
// size, in pixels
2021-12-25 10:04:45 +08:00
_startSize = 54.0f;
2019-11-23 20:27:39 +08:00
_startSizeVar = 10.0f;
2021-12-25 10:04:45 +08:00
_endSize = START_SIZE_EQUAL_TO_END_SIZE;
2019-11-23 20:27:39 +08:00
// emits per frame
2021-12-25 10:04:45 +08:00
_emissionRate = _totalParticles / _life;
2019-11-23 20:27:39 +08:00
// color of particles
2021-12-25 10:04:45 +08:00
_startColor.r = 0.76f;
_startColor.g = 0.25f;
_startColor.b = 0.12f;
_startColor.a = 1.0f;
2019-11-23 20:27:39 +08:00
_startColorVar.r = 0.0f;
_startColorVar.g = 0.0f;
_startColorVar.b = 0.0f;
_startColorVar.a = 0.0f;
2021-12-25 10:04:45 +08:00
_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;
2019-11-23 20:27:39 +08:00
Texture2D* texture = getDefaultTexture();
if (texture != nullptr)
{
setTexture(texture);
}
2021-12-25 10:04:45 +08:00
2019-11-23 20:27:39 +08:00
// additive
this->setBlendAdditive(true);
return true;
}
return false;
}
//
// ParticleFireworks
//
ParticleFireworks* ParticleFireworks::create()
{
2021-12-08 00:11:53 +08:00
ParticleFireworks* ret = new ParticleFireworks();
if (ret->init())
2019-11-23 20:27:39 +08:00
{
ret->autorelease();
}
else
{
2022-07-16 10:43:05 +08:00
AX_SAFE_DELETE(ret);
2019-11-23 20:27:39 +08:00
}
return ret;
}
ParticleFireworks* ParticleFireworks::createWithTotalParticles(int numberOfParticles)
{
2021-12-08 00:11:53 +08:00
ParticleFireworks* ret = new ParticleFireworks();
if (ret->initWithTotalParticles(numberOfParticles))
2019-11-23 20:27:39 +08:00
{
ret->autorelease();
}
else
{
2022-07-16 10:43:05 +08:00
AX_SAFE_DELETE(ret);
2019-11-23 20:27:39 +08:00
}
return ret;
}
bool ParticleFireworks::initWithTotalParticles(int numberOfParticles)
{
2021-12-25 10:04:45 +08:00
if (ParticleSystemQuad::initWithTotalParticles(numberOfParticles))
2019-11-23 20:27:39 +08:00
{
// duration
2021-12-25 10:04:45 +08:00
_duration = DURATION_INFINITY;
2019-11-23 20:27:39 +08:00
// Gravity Mode
this->_emitterMode = Mode::GRAVITY;
// Gravity Mode: gravity
this->modeA.gravity.set(0.0f, -90.0f);
// Gravity Mode: radial
2021-12-25 10:04:45 +08:00
this->modeA.radialAccel = 0.0f;
2019-11-23 20:27:39 +08:00
this->modeA.radialAccelVar = 0.0f;
// Gravity Mode: speed of particles
2021-12-25 10:04:45 +08:00
this->modeA.speed = 180.0f;
2019-11-23 20:27:39 +08:00
this->modeA.speedVar = 50.0f;
// emitter position
2021-10-23 23:27:14 +08:00
Vec2 winSize = _director->getWinSize();
2021-12-25 10:04:45 +08:00
this->setPosition(winSize.width / 2, winSize.height / 2);
2019-11-23 20:27:39 +08:00
// angle
2021-12-25 10:04:45 +08:00
this->_angle = 90.0f;
2019-11-23 20:27:39 +08:00
this->_angleVar = 20.0f;
// life of particles
2021-12-25 10:04:45 +08:00
this->_life = 3.5f;
2019-11-23 20:27:39 +08:00
this->_lifeVar = 1.0f;
// emits per frame
2021-12-25 10:04:45 +08:00
this->_emissionRate = _totalParticles / _life;
2019-11-23 20:27:39 +08:00
// color of particles
2021-12-25 10:04:45 +08:00
_startColor.r = 0.5f;
_startColor.g = 0.5f;
_startColor.b = 0.5f;
_startColor.a = 1.0f;
2019-11-23 20:27:39 +08:00
_startColorVar.r = 0.5f;
_startColorVar.g = 0.5f;
_startColorVar.b = 0.5f;
_startColorVar.a = 0.1f;
2021-12-25 10:04:45 +08:00
_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;
2019-11-23 20:27:39 +08:00
// size, in pixels
2021-12-25 10:04:45 +08:00
_startSize = 8.0f;
2019-11-23 20:27:39 +08:00
_startSizeVar = 2.0f;
2021-12-25 10:04:45 +08:00
_endSize = START_SIZE_EQUAL_TO_END_SIZE;
2019-11-23 20:27:39 +08:00
Texture2D* texture = getDefaultTexture();
if (texture != nullptr)
{
setTexture(texture);
}
// additive
this->setBlendAdditive(false);
return true;
}
return false;
}
//
// ParticleSun
//
ParticleSun* ParticleSun::create()
{
2021-12-08 00:11:53 +08:00
ParticleSun* ret = new ParticleSun();
if (ret->init())
2019-11-23 20:27:39 +08:00
{
ret->autorelease();
}
else
{
2022-07-16 10:43:05 +08:00
AX_SAFE_DELETE(ret);
2019-11-23 20:27:39 +08:00
}
return ret;
}
ParticleSun* ParticleSun::createWithTotalParticles(int numberOfParticles)
{
2021-12-08 00:11:53 +08:00
ParticleSun* ret = new ParticleSun();
if (ret->initWithTotalParticles(numberOfParticles))
2019-11-23 20:27:39 +08:00
{
ret->autorelease();
}
else
{
2022-07-16 10:43:05 +08:00
AX_SAFE_DELETE(ret);
2019-11-23 20:27:39 +08:00
}
return ret;
}
bool ParticleSun::initWithTotalParticles(int numberOfParticles)
{
2021-12-25 10:04:45 +08:00
if (ParticleSystemQuad::initWithTotalParticles(numberOfParticles))
2019-11-23 20:27:39 +08:00
{
// additive
this->setBlendAdditive(true);
// duration
_duration = DURATION_INFINITY;
// Gravity Mode
setEmitterMode(Mode::GRAVITY);
// Gravity Mode: gravity
2021-12-25 10:04:45 +08:00
setGravity(Vec2(0, 0));
2019-11-23 20:27:39 +08:00
// Gravity mode: radial acceleration
setRadialAccel(0);
setRadialAccelVar(0);
// Gravity mode: speed of particles
setSpeed(20);
setSpeedVar(5);
// angle
2021-12-25 10:04:45 +08:00
_angle = 90;
2019-11-23 20:27:39 +08:00
_angleVar = 360;
// emitter position
2021-10-23 23:27:14 +08:00
Vec2 winSize = _director->getWinSize();
2021-12-25 10:04:45 +08:00
this->setPosition(winSize.width / 2, winSize.height / 2);
2019-11-23 20:27:39 +08:00
setPosVar(Vec2::ZERO);
// life of particles
2021-12-25 10:04:45 +08:00
_life = 1;
2019-11-23 20:27:39 +08:00
_lifeVar = 0.5f;
// size, in pixels
2021-12-25 10:04:45 +08:00
_startSize = 30.0f;
2019-11-23 20:27:39 +08:00
_startSizeVar = 10.0f;
2021-12-25 10:04:45 +08:00
_endSize = START_SIZE_EQUAL_TO_END_SIZE;
2019-11-23 20:27:39 +08:00
// emits per seconds
2021-12-25 10:04:45 +08:00
_emissionRate = _totalParticles / _life;
2019-11-23 20:27:39 +08:00
// color of particles
2021-12-25 10:04:45 +08:00
_startColor.r = 0.76f;
_startColor.g = 0.25f;
_startColor.b = 0.12f;
_startColor.a = 1.0f;
2019-11-23 20:27:39 +08:00
_startColorVar.r = 0.0f;
_startColorVar.g = 0.0f;
_startColorVar.b = 0.0f;
_startColorVar.a = 0.0f;
2021-12-25 10:04:45 +08:00
_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;
2019-11-23 20:27:39 +08:00
Texture2D* texture = getDefaultTexture();
if (texture != nullptr)
{
setTexture(texture);
}
return true;
}
return false;
}
//
// ParticleGalaxy
//
ParticleGalaxy* ParticleGalaxy::create()
{
2021-12-08 00:11:53 +08:00
ParticleGalaxy* ret = new ParticleGalaxy();
if (ret->init())
2019-11-23 20:27:39 +08:00
{
ret->autorelease();
}
else
{
2022-07-16 10:43:05 +08:00
AX_SAFE_DELETE(ret);
2019-11-23 20:27:39 +08:00
}
return ret;
}
ParticleGalaxy* ParticleGalaxy::createWithTotalParticles(int numberOfParticles)
{
2021-12-08 00:11:53 +08:00
ParticleGalaxy* ret = new ParticleGalaxy();
if (ret->initWithTotalParticles(numberOfParticles))
2019-11-23 20:27:39 +08:00
{
ret->autorelease();
}
else
{
2022-07-16 10:43:05 +08:00
AX_SAFE_DELETE(ret);
2019-11-23 20:27:39 +08:00
}
return ret;
}
bool ParticleGalaxy::initWithTotalParticles(int numberOfParticles)
{
2021-12-25 10:04:45 +08:00
if (ParticleSystemQuad::initWithTotalParticles(numberOfParticles))
2019-11-23 20:27:39 +08:00
{
// duration
_duration = DURATION_INFINITY;
// Gravity Mode
setEmitterMode(Mode::GRAVITY);
// Gravity Mode: gravity
2021-12-25 10:04:45 +08:00
setGravity(Vec2(0, 0));
2019-11-23 20:27:39 +08:00
// Gravity Mode: speed of particles
setSpeed(60);
setSpeedVar(10);
// Gravity Mode: radial
setRadialAccel(-80);
setRadialAccelVar(0);
// Gravity Mode: tangential
setTangentialAccel(80);
setTangentialAccelVar(0);
// angle
2021-12-25 10:04:45 +08:00
_angle = 90;
2019-11-23 20:27:39 +08:00
_angleVar = 360;
// emitter position
2021-10-23 23:27:14 +08:00
Vec2 winSize = _director->getWinSize();
2021-12-25 10:04:45 +08:00
this->setPosition(winSize.width / 2, winSize.height / 2);
2019-11-23 20:27:39 +08:00
setPosVar(Vec2::ZERO);
// life of particles
2021-12-25 10:04:45 +08:00
_life = 4;
2019-11-23 20:27:39 +08:00
_lifeVar = 1;
// size, in pixels
2021-12-25 10:04:45 +08:00
_startSize = 37.0f;
2019-11-23 20:27:39 +08:00
_startSizeVar = 10.0f;
2021-12-25 10:04:45 +08:00
_endSize = START_SIZE_EQUAL_TO_END_SIZE;
2019-11-23 20:27:39 +08:00
// emits per second
2021-12-25 10:04:45 +08:00
_emissionRate = _totalParticles / _life;
2019-11-23 20:27:39 +08:00
// color of particles
2021-12-25 10:04:45 +08:00
_startColor.r = 0.12f;
_startColor.g = 0.25f;
_startColor.b = 0.76f;
_startColor.a = 1.0f;
2019-11-23 20:27:39 +08:00
_startColorVar.r = 0.0f;
_startColorVar.g = 0.0f;
_startColorVar.b = 0.0f;
_startColorVar.a = 0.0f;
2021-12-25 10:04:45 +08:00
_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;
2019-11-23 20:27:39 +08:00
Texture2D* texture = getDefaultTexture();
if (texture != nullptr)
{
setTexture(texture);
}
// additive
this->setBlendAdditive(true);
return true;
}
return false;
}
//
// ParticleFlower
//
ParticleFlower* ParticleFlower::create()
{
2021-12-08 00:11:53 +08:00
ParticleFlower* ret = new ParticleFlower();
if (ret->init())
2019-11-23 20:27:39 +08:00
{
ret->autorelease();
}
else
{
2022-07-16 10:43:05 +08:00
AX_SAFE_DELETE(ret);
2019-11-23 20:27:39 +08:00
}
return ret;
}
ParticleFlower* ParticleFlower::createWithTotalParticles(int numberOfParticles)
{
2021-12-08 00:11:53 +08:00
ParticleFlower* ret = new ParticleFlower();
if (ret->initWithTotalParticles(numberOfParticles))
2019-11-23 20:27:39 +08:00
{
ret->autorelease();
}
else
{
2022-07-16 10:43:05 +08:00
AX_SAFE_DELETE(ret);
2019-11-23 20:27:39 +08:00
}
return ret;
}
bool ParticleFlower::initWithTotalParticles(int numberOfParticles)
{
2021-12-25 10:04:45 +08:00
if (ParticleSystemQuad::initWithTotalParticles(numberOfParticles))
2019-11-23 20:27:39 +08:00
{
// duration
_duration = DURATION_INFINITY;
// Gravity Mode
setEmitterMode(Mode::GRAVITY);
// Gravity Mode: gravity
2021-12-25 10:04:45 +08:00
setGravity(Vec2(0, 0));
2019-11-23 20:27:39 +08:00
// Gravity Mode: speed of particles
setSpeed(80);
setSpeedVar(10);
// Gravity Mode: radial
setRadialAccel(-60);
setRadialAccelVar(0);
// Gravity Mode: tangential
setTangentialAccel(15);
setTangentialAccelVar(0);
// angle
2021-12-25 10:04:45 +08:00
_angle = 90;
2019-11-23 20:27:39 +08:00
_angleVar = 360;
// emitter position
2021-10-23 23:27:14 +08:00
Vec2 winSize = _director->getWinSize();
2021-12-25 10:04:45 +08:00
this->setPosition(winSize.width / 2, winSize.height / 2);
2019-11-23 20:27:39 +08:00
setPosVar(Vec2::ZERO);
// life of particles
2021-12-25 10:04:45 +08:00
_life = 4;
2019-11-23 20:27:39 +08:00
_lifeVar = 1;
// size, in pixels
2021-12-25 10:04:45 +08:00
_startSize = 30.0f;
2019-11-23 20:27:39 +08:00
_startSizeVar = 10.0f;
2021-12-25 10:04:45 +08:00
_endSize = START_SIZE_EQUAL_TO_END_SIZE;
2019-11-23 20:27:39 +08:00
// emits per second
2021-12-25 10:04:45 +08:00
_emissionRate = _totalParticles / _life;
2019-11-23 20:27:39 +08:00
// color of particles
2021-12-25 10:04:45 +08:00
_startColor.r = 0.50f;
_startColor.g = 0.50f;
_startColor.b = 0.50f;
_startColor.a = 1.0f;
2019-11-23 20:27:39 +08:00
_startColorVar.r = 0.5f;
_startColorVar.g = 0.5f;
_startColorVar.b = 0.5f;
_startColorVar.a = 0.5f;
2021-12-25 10:04:45 +08:00
_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;
2019-11-23 20:27:39 +08:00
Texture2D* texture = getDefaultTexture();
if (texture != nullptr)
{
setTexture(texture);
}
// additive
this->setBlendAdditive(true);
return true;
}
return false;
}
//
// ParticleMeteor
//
2021-12-25 10:04:45 +08:00
ParticleMeteor* ParticleMeteor::create()
2019-11-23 20:27:39 +08:00
{
2021-12-25 10:04:45 +08:00
ParticleMeteor* ret = new ParticleMeteor();
2021-12-08 00:11:53 +08:00
if (ret->init())
2019-11-23 20:27:39 +08:00
{
ret->autorelease();
}
else
{
2022-07-16 10:43:05 +08:00
AX_SAFE_DELETE(ret);
2019-11-23 20:27:39 +08:00
}
return ret;
}
ParticleMeteor* ParticleMeteor::createWithTotalParticles(int numberOfParticles)
{
2021-12-08 00:11:53 +08:00
ParticleMeteor* ret = new ParticleMeteor();
if (ret->initWithTotalParticles(numberOfParticles))
2019-11-23 20:27:39 +08:00
{
ret->autorelease();
}
else
{
2022-07-16 10:43:05 +08:00
AX_SAFE_DELETE(ret);
2019-11-23 20:27:39 +08:00
}
return ret;
}
bool ParticleMeteor::initWithTotalParticles(int numberOfParticles)
{
2021-12-25 10:04:45 +08:00
if (ParticleSystemQuad::initWithTotalParticles(numberOfParticles))
2019-11-23 20:27:39 +08:00
{
// duration
_duration = DURATION_INFINITY;
// Gravity Mode
setEmitterMode(Mode::GRAVITY);
// Gravity Mode: gravity
2021-12-25 10:04:45 +08:00
setGravity(Vec2(-200, 200));
2019-11-23 20:27:39 +08:00
// Gravity Mode: speed of particles
setSpeed(15);
setSpeedVar(5);
// Gravity Mode: radial
setRadialAccel(0);
setRadialAccelVar(0);
// Gravity Mode: tangential
setTangentialAccel(0);
setTangentialAccelVar(0);
// angle
2021-12-25 10:04:45 +08:00
_angle = 90;
2019-11-23 20:27:39 +08:00
_angleVar = 360;
// emitter position
2021-10-23 23:27:14 +08:00
Vec2 winSize = _director->getWinSize();
2021-12-25 10:04:45 +08:00
this->setPosition(winSize.width / 2, winSize.height / 2);
2019-11-23 20:27:39 +08:00
setPosVar(Vec2::ZERO);
// life of particles
2021-12-25 10:04:45 +08:00
_life = 2;
2019-11-23 20:27:39 +08:00
_lifeVar = 1;
// size, in pixels
2021-12-25 10:04:45 +08:00
_startSize = 60.0f;
2019-11-23 20:27:39 +08:00
_startSizeVar = 10.0f;
2021-12-25 10:04:45 +08:00
_endSize = START_SIZE_EQUAL_TO_END_SIZE;
2019-11-23 20:27:39 +08:00
// emits per second
2021-12-25 10:04:45 +08:00
_emissionRate = _totalParticles / _life;
2019-11-23 20:27:39 +08:00
// color of particles
2021-12-25 10:04:45 +08:00
_startColor.r = 0.2f;
_startColor.g = 0.4f;
_startColor.b = 0.7f;
_startColor.a = 1.0f;
2019-11-23 20:27:39 +08:00
_startColorVar.r = 0.0f;
_startColorVar.g = 0.0f;
_startColorVar.b = 0.2f;
_startColorVar.a = 0.1f;
2021-12-25 10:04:45 +08:00
_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;
2019-11-23 20:27:39 +08:00
Texture2D* texture = getDefaultTexture();
if (texture != nullptr)
{
setTexture(texture);
}
// additive
this->setBlendAdditive(true);
return true;
}
return false;
}
//
// ParticleSpiral
//
ParticleSpiral* ParticleSpiral::create()
{
2021-12-08 00:11:53 +08:00
ParticleSpiral* ret = new ParticleSpiral();
if (ret->init())
2019-11-23 20:27:39 +08:00
{
ret->autorelease();
}
else
{
2022-07-16 10:43:05 +08:00
AX_SAFE_DELETE(ret);
2019-11-23 20:27:39 +08:00
}
return ret;
}
ParticleSpiral* ParticleSpiral::createWithTotalParticles(int numberOfParticles)
{
2021-12-08 00:11:53 +08:00
ParticleSpiral* ret = new ParticleSpiral();
if (ret->initWithTotalParticles(numberOfParticles))
2019-11-23 20:27:39 +08:00
{
ret->autorelease();
}
else
{
2022-07-16 10:43:05 +08:00
AX_SAFE_DELETE(ret);
2019-11-23 20:27:39 +08:00
}
return ret;
}
bool ParticleSpiral::initWithTotalParticles(int numberOfParticles)
{
2021-12-25 10:04:45 +08:00
if (ParticleSystemQuad::initWithTotalParticles(numberOfParticles))
2019-11-23 20:27:39 +08:00
{
// duration
_duration = DURATION_INFINITY;
// Gravity Mode
setEmitterMode(Mode::GRAVITY);
// Gravity Mode: gravity
2021-12-25 10:04:45 +08:00
setGravity(Vec2(0, 0));
2019-11-23 20:27:39 +08:00
// Gravity Mode: speed of particles
setSpeed(150);
setSpeedVar(0);
// Gravity Mode: radial
setRadialAccel(-380);
setRadialAccelVar(0);
// Gravity Mode: tangential
setTangentialAccel(45);
setTangentialAccelVar(0);
// angle
2021-12-25 10:04:45 +08:00
_angle = 90;
2019-11-23 20:27:39 +08:00
_angleVar = 0;
// emitter position
2021-10-23 23:27:14 +08:00
Vec2 winSize = _director->getWinSize();
2021-12-25 10:04:45 +08:00
this->setPosition(winSize.width / 2, winSize.height / 2);
2019-11-23 20:27:39 +08:00
setPosVar(Vec2::ZERO);
// life of particles
2021-12-25 10:04:45 +08:00
_life = 12;
2019-11-23 20:27:39 +08:00
_lifeVar = 0;
// size, in pixels
2021-12-25 10:04:45 +08:00
_startSize = 20.0f;
2019-11-23 20:27:39 +08:00
_startSizeVar = 0.0f;
2021-12-25 10:04:45 +08:00
_endSize = START_SIZE_EQUAL_TO_END_SIZE;
2019-11-23 20:27:39 +08:00
// emits per second
2021-12-25 10:04:45 +08:00
_emissionRate = _totalParticles / _life;
2019-11-23 20:27:39 +08:00
// color of particles
2021-12-25 10:04:45 +08:00
_startColor.r = 0.5f;
_startColor.g = 0.5f;
_startColor.b = 0.5f;
_startColor.a = 1.0f;
2019-11-23 20:27:39 +08:00
_startColorVar.r = 0.5f;
_startColorVar.g = 0.5f;
_startColorVar.b = 0.5f;
_startColorVar.a = 0.0f;
2021-12-25 10:04:45 +08:00
_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;
2019-11-23 20:27:39 +08:00
Texture2D* texture = getDefaultTexture();
if (texture != nullptr)
{
setTexture(texture);
}
// additive
this->setBlendAdditive(false);
return true;
}
return false;
}
//
// ParticleExplosion
//
ParticleExplosion* ParticleExplosion::create()
{
2021-12-08 00:11:53 +08:00
ParticleExplosion* ret = new ParticleExplosion();
if (ret->init())
2019-11-23 20:27:39 +08:00
{
ret->autorelease();
}
else
{
2022-07-16 10:43:05 +08:00
AX_SAFE_DELETE(ret);
2019-11-23 20:27:39 +08:00
}
return ret;
}
ParticleExplosion* ParticleExplosion::createWithTotalParticles(int numberOfParticles)
{
2021-12-08 00:11:53 +08:00
ParticleExplosion* ret = new ParticleExplosion();
if (ret->initWithTotalParticles(numberOfParticles))
2019-11-23 20:27:39 +08:00
{
ret->autorelease();
}
else
{
2022-07-16 10:43:05 +08:00
AX_SAFE_DELETE(ret);
2019-11-23 20:27:39 +08:00
}
return ret;
}
bool ParticleExplosion::initWithTotalParticles(int numberOfParticles)
{
2021-12-25 10:04:45 +08:00
if (ParticleSystemQuad::initWithTotalParticles(numberOfParticles))
2019-11-23 20:27:39 +08:00
{
// duration
_duration = 0.1f;
setEmitterMode(Mode::GRAVITY);
// Gravity Mode: gravity
2021-12-25 10:04:45 +08:00
setGravity(Vec2(0, 0));
2019-11-23 20:27:39 +08:00
// Gravity Mode: speed of particles
setSpeed(70);
setSpeedVar(40);
// Gravity Mode: radial
setRadialAccel(0);
setRadialAccelVar(0);
// Gravity Mode: tangential
setTangentialAccel(0);
setTangentialAccelVar(0);
// angle
2021-12-25 10:04:45 +08:00
_angle = 90;
2019-11-23 20:27:39 +08:00
_angleVar = 360;
// emitter position
2021-10-23 23:27:14 +08:00
Vec2 winSize = _director->getWinSize();
2021-12-25 10:04:45 +08:00
this->setPosition(winSize.width / 2, winSize.height / 2);
2019-11-23 20:27:39 +08:00
setPosVar(Vec2::ZERO);
// life of particles
2021-12-25 10:04:45 +08:00
_life = 5.0f;
2019-11-23 20:27:39 +08:00
_lifeVar = 2;
// size, in pixels
2021-12-25 10:04:45 +08:00
_startSize = 15.0f;
2019-11-23 20:27:39 +08:00
_startSizeVar = 10.0f;
2021-12-25 10:04:45 +08:00
_endSize = START_SIZE_EQUAL_TO_END_SIZE;
2019-11-23 20:27:39 +08:00
// emits per second
2021-12-25 10:04:45 +08:00
_emissionRate = _totalParticles / _duration;
2019-11-23 20:27:39 +08:00
// color of particles
2021-12-25 10:04:45 +08:00
_startColor.r = 0.7f;
_startColor.g = 0.1f;
_startColor.b = 0.2f;
_startColor.a = 1.0f;
2019-11-23 20:27:39 +08:00
_startColorVar.r = 0.5f;
_startColorVar.g = 0.5f;
_startColorVar.b = 0.5f;
_startColorVar.a = 0.0f;
2021-12-25 10:04:45 +08:00
_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;
2019-11-23 20:27:39 +08:00
Texture2D* texture = getDefaultTexture();
if (texture != nullptr)
{
setTexture(texture);
}
// additive
this->setBlendAdditive(false);
return true;
}
return false;
}
//
// ParticleSmoke
//
ParticleSmoke* ParticleSmoke::create()
{
2021-12-08 00:11:53 +08:00
ParticleSmoke* ret = new ParticleSmoke();
if (ret->init())
2019-11-23 20:27:39 +08:00
{
ret->autorelease();
}
else
{
2022-07-16 10:43:05 +08:00
AX_SAFE_DELETE(ret);
2019-11-23 20:27:39 +08:00
}
return ret;
}
ParticleSmoke* ParticleSmoke::createWithTotalParticles(int numberOfParticles)
{
2021-12-08 00:11:53 +08:00
ParticleSmoke* ret = new ParticleSmoke();
if (ret->initWithTotalParticles(numberOfParticles))
2019-11-23 20:27:39 +08:00
{
ret->autorelease();
}
else
{
2022-07-16 10:43:05 +08:00
AX_SAFE_DELETE(ret);
2019-11-23 20:27:39 +08:00
}
return ret;
}
bool ParticleSmoke::initWithTotalParticles(int numberOfParticles)
{
2021-12-25 10:04:45 +08:00
if (ParticleSystemQuad::initWithTotalParticles(numberOfParticles))
2019-11-23 20:27:39 +08:00
{
// duration
_duration = DURATION_INFINITY;
// Emitter mode: Gravity Mode
setEmitterMode(Mode::GRAVITY);
// Gravity Mode: gravity
2021-12-25 10:04:45 +08:00
setGravity(Vec2(0, 0));
2019-11-23 20:27:39 +08:00
// Gravity Mode: radial acceleration
setRadialAccel(0);
setRadialAccelVar(0);
// Gravity Mode: speed of particles
setSpeed(25);
setSpeedVar(10);
// angle
2021-12-25 10:04:45 +08:00
_angle = 90;
2019-11-23 20:27:39 +08:00
_angleVar = 5;
// emitter position
2021-10-23 23:27:14 +08:00
Vec2 winSize = _director->getWinSize();
2021-12-25 10:04:45 +08:00
this->setPosition(winSize.width / 2, 0);
2019-11-23 20:27:39 +08:00
setPosVar(Vec2(20, 0));
// life of particles
2021-12-25 10:04:45 +08:00
_life = 4;
2019-11-23 20:27:39 +08:00
_lifeVar = 1;
// size, in pixels
2021-12-25 10:04:45 +08:00
_startSize = 60.0f;
2019-11-23 20:27:39 +08:00
_startSizeVar = 10.0f;
2021-12-25 10:04:45 +08:00
_endSize = START_SIZE_EQUAL_TO_END_SIZE;
2019-11-23 20:27:39 +08:00
// emits per frame
2021-12-25 10:04:45 +08:00
_emissionRate = _totalParticles / _life;
2019-11-23 20:27:39 +08:00
// color of particles
2021-12-25 10:04:45 +08:00
_startColor.r = 0.8f;
_startColor.g = 0.8f;
_startColor.b = 0.8f;
_startColor.a = 1.0f;
2019-11-23 20:27:39 +08:00
_startColorVar.r = 0.02f;
_startColorVar.g = 0.02f;
_startColorVar.b = 0.02f;
_startColorVar.a = 0.0f;
2021-12-25 10:04:45 +08:00
_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;
2019-11-23 20:27:39 +08:00
Texture2D* texture = getDefaultTexture();
if (texture != nullptr)
{
setTexture(texture);
}
// additive
this->setBlendAdditive(false);
return true;
}
return false;
}
//
// ParticleSnow
//
ParticleSnow* ParticleSnow::create()
{
2021-12-08 00:11:53 +08:00
ParticleSnow* ret = new ParticleSnow();
if (ret->init())
2019-11-23 20:27:39 +08:00
{
ret->autorelease();
}
else
{
2022-07-16 10:43:05 +08:00
AX_SAFE_DELETE(ret);
2019-11-23 20:27:39 +08:00
}
return ret;
}
ParticleSnow* ParticleSnow::createWithTotalParticles(int numberOfParticles)
{
2021-12-08 00:11:53 +08:00
ParticleSnow* ret = new ParticleSnow();
if (ret->initWithTotalParticles(numberOfParticles))
2019-11-23 20:27:39 +08:00
{
ret->autorelease();
}
else
{
2022-07-16 10:43:05 +08:00
AX_SAFE_DELETE(ret);
2019-11-23 20:27:39 +08:00
}
return ret;
}
bool ParticleSnow::initWithTotalParticles(int numberOfParticles)
{
2021-12-25 10:04:45 +08:00
if (ParticleSystemQuad::initWithTotalParticles(numberOfParticles))
2019-11-23 20:27:39 +08:00
{
// duration
_duration = DURATION_INFINITY;
// set gravity mode.
setEmitterMode(Mode::GRAVITY);
// Gravity Mode: gravity
2021-12-25 10:04:45 +08:00
setGravity(Vec2(0, -1));
2019-11-23 20:27:39 +08:00
// 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
2021-10-23 23:27:14 +08:00
Vec2 winSize = _director->getWinSize();
2021-12-25 10:04:45 +08:00
this->setPosition(winSize.width / 2, winSize.height + 10);
setPosVar(Vec2(winSize.width / 2, 0.0f));
2019-11-23 20:27:39 +08:00
// angle
2021-12-25 10:04:45 +08:00
_angle = -90;
2019-11-23 20:27:39 +08:00
_angleVar = 5;
// life of particles
2021-12-25 10:04:45 +08:00
_life = 45;
2019-11-23 20:27:39 +08:00
_lifeVar = 15;
// size, in pixels
2021-12-25 10:04:45 +08:00
_startSize = 10.0f;
2019-11-23 20:27:39 +08:00
_startSizeVar = 5.0f;
2021-12-25 10:04:45 +08:00
_endSize = START_SIZE_EQUAL_TO_END_SIZE;
2019-11-23 20:27:39 +08:00
// emits per second
_emissionRate = 10;
// color of particles
2021-12-25 10:04:45 +08:00
_startColor.r = 1.0f;
_startColor.g = 1.0f;
_startColor.b = 1.0f;
_startColor.a = 1.0f;
2019-11-23 20:27:39 +08:00
_startColorVar.r = 0.0f;
_startColorVar.g = 0.0f;
_startColorVar.b = 0.0f;
_startColorVar.a = 0.0f;
2021-12-25 10:04:45 +08:00
_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;
2019-11-23 20:27:39 +08:00
Texture2D* texture = getDefaultTexture();
if (texture != nullptr)
{
setTexture(texture);
}
// additive
this->setBlendAdditive(false);
return true;
}
return false;
}
//
// ParticleRain
//
ParticleRain* ParticleRain::create()
{
2021-12-08 00:11:53 +08:00
ParticleRain* ret = new ParticleRain();
if (ret->init())
2019-11-23 20:27:39 +08:00
{
ret->autorelease();
}
else
{
2022-07-16 10:43:05 +08:00
AX_SAFE_DELETE(ret);
2019-11-23 20:27:39 +08:00
}
return ret;
}
ParticleRain* ParticleRain::createWithTotalParticles(int numberOfParticles)
{
2021-12-08 00:11:53 +08:00
ParticleRain* ret = new ParticleRain();
if (ret->initWithTotalParticles(numberOfParticles))
2019-11-23 20:27:39 +08:00
{
ret->autorelease();
}
else
{
2022-07-16 10:43:05 +08:00
AX_SAFE_DELETE(ret);
2019-11-23 20:27:39 +08:00
}
return ret;
}
bool ParticleRain::initWithTotalParticles(int numberOfParticles)
{
2021-12-25 10:04:45 +08:00
if (ParticleSystemQuad::initWithTotalParticles(numberOfParticles))
2019-11-23 20:27:39 +08:00
{
// duration
_duration = DURATION_INFINITY;
setEmitterMode(Mode::GRAVITY);
// Gravity Mode: gravity
2021-12-25 10:04:45 +08:00
setGravity(Vec2(10, -10));
2019-11-23 20:27:39 +08:00
// Gravity Mode: radial
setRadialAccel(0);
setRadialAccelVar(1);
// Gravity Mode: tangential
setTangentialAccel(0);
setTangentialAccelVar(1);
// Gravity Mode: speed of particles
setSpeed(130);
setSpeedVar(30);
// angle
2021-12-25 10:04:45 +08:00
_angle = -90;
2019-11-23 20:27:39 +08:00
_angleVar = 5;
// emitter position
2021-10-23 23:27:14 +08:00
Vec2 winSize = _director->getWinSize();
2021-12-25 10:04:45 +08:00
this->setPosition(winSize.width / 2, winSize.height);
setPosVar(Vec2(winSize.width / 2, 0.0f));
2019-11-23 20:27:39 +08:00
// life of particles
2021-12-25 10:04:45 +08:00
_life = 4.5f;
2019-11-23 20:27:39 +08:00
_lifeVar = 0;
// size, in pixels
2021-12-25 10:04:45 +08:00
_startSize = 4.0f;
2019-11-23 20:27:39 +08:00
_startSizeVar = 2.0f;
2021-12-25 10:04:45 +08:00
_endSize = START_SIZE_EQUAL_TO_END_SIZE;
2019-11-23 20:27:39 +08:00
// emits per second
_emissionRate = 20;
// color of particles
2021-12-25 10:04:45 +08:00
_startColor.r = 0.7f;
_startColor.g = 0.8f;
_startColor.b = 1.0f;
_startColor.a = 1.0f;
2019-11-23 20:27:39 +08:00
_startColorVar.r = 0.0f;
_startColorVar.g = 0.0f;
_startColorVar.b = 0.0f;
_startColorVar.a = 0.0f;
2021-12-25 10:04:45 +08:00
_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;
2019-11-23 20:27:39 +08:00
Texture2D* texture = getDefaultTexture();
if (texture != nullptr)
{
setTexture(texture);
}
// additive
this->setBlendAdditive(false);
return true;
}
return false;
}
}