2011-03-19 05:07:16 +03:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2008-2010 Ricardo Quesada
|
2014-01-07 07:25:07 +04:00
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
2011-07-04 15:20:16 +04:00
|
|
|
Copyright (c) 2011 Zynga Inc.
|
2017-02-14 09:36:57 +03:00
|
|
|
Copyright (c) 2013-2017 Chukong Technologies Inc.
|
2011-03-19 05:07:16 +03:00
|
|
|
|
|
|
|
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.
|
|
|
|
****************************************************************************/
|
2014-05-17 01:36:00 +04:00
|
|
|
|
|
|
|
#include "2d/CCParticleExamples.h"
|
2014-04-30 04:37:36 +04:00
|
|
|
#include "base/CCDirector.h"
|
2014-05-17 01:36:00 +04:00
|
|
|
#include "base/firePngData.h"
|
|
|
|
#include "renderer/CCTextureCache.h"
|
2012-04-18 14:43:45 +04:00
|
|
|
|
|
|
|
NS_CC_BEGIN
|
2010-12-28 09:04:28 +03:00
|
|
|
//
|
|
|
|
// ParticleFire
|
|
|
|
//
|
2012-11-01 18:17:12 +04:00
|
|
|
|
2013-06-20 10:13:12 +04:00
|
|
|
static Texture2D* getDefaultTexture()
|
2012-11-08 08:02:58 +04:00
|
|
|
{
|
2013-12-18 13:47:20 +04:00
|
|
|
Texture2D* texture = nullptr;
|
|
|
|
Image* image = nullptr;
|
2012-11-08 08:02:58 +04:00
|
|
|
do
|
|
|
|
{
|
2013-12-24 06:51:47 +04:00
|
|
|
const std::string key = "/__firePngData";
|
2013-11-07 15:11:09 +04:00
|
|
|
texture = Director::getInstance()->getTextureCache()->getTextureForKey(key);
|
2013-12-18 13:47:20 +04:00
|
|
|
CC_BREAK_IF(texture != nullptr);
|
2012-11-08 08:02:58 +04:00
|
|
|
|
2014-08-28 03:31:57 +04:00
|
|
|
image = new (std::nothrow) Image();
|
2013-12-18 13:47:20 +04:00
|
|
|
CC_BREAK_IF(nullptr == image);
|
2017-02-09 05:57:01 +03:00
|
|
|
bool ret = image->initWithImageData(__firePngData, sizeof(__firePngData));
|
2013-12-18 13:47:20 +04:00
|
|
|
CC_BREAK_IF(!ret);
|
2012-11-08 08:02:58 +04:00
|
|
|
|
2013-12-18 13:47:20 +04:00
|
|
|
texture = Director::getInstance()->getTextureCache()->addImage(image, key);
|
2012-11-08 08:02:58 +04:00
|
|
|
} while (0);
|
|
|
|
|
2013-12-18 13:47:20 +04:00
|
|
|
CC_SAFE_RELEASE(image);
|
2012-12-27 11:42:55 +04:00
|
|
|
|
2013-07-26 02:53:24 +04:00
|
|
|
return texture;
|
2012-11-08 08:02:58 +04:00
|
|
|
}
|
|
|
|
|
2013-06-20 10:13:12 +04:00
|
|
|
ParticleFire* ParticleFire::create()
|
2012-11-01 18:17:12 +04:00
|
|
|
{
|
2014-08-28 03:31:57 +04:00
|
|
|
ParticleFire* ret = new (std::nothrow) ParticleFire();
|
2013-12-18 13:47:20 +04:00
|
|
|
if (ret && ret->init())
|
2012-11-01 18:17:12 +04:00
|
|
|
{
|
2013-12-18 13:47:20 +04:00
|
|
|
ret->autorelease();
|
2012-11-01 18:17:12 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-18 13:47:20 +04:00
|
|
|
CC_SAFE_DELETE(ret);
|
2012-11-01 18:17:12 +04:00
|
|
|
}
|
2013-12-18 13:47:20 +04:00
|
|
|
return ret;
|
2012-11-01 18:17:12 +04:00
|
|
|
}
|
|
|
|
|
2013-11-16 01:14:12 +04:00
|
|
|
ParticleFire* ParticleFire::createWithTotalParticles(int numberOfParticles)
|
2012-11-08 08:02:58 +04:00
|
|
|
{
|
2014-08-28 03:31:57 +04:00
|
|
|
ParticleFire* ret = new (std::nothrow) ParticleFire();
|
2013-12-18 13:47:20 +04:00
|
|
|
if (ret && ret->initWithTotalParticles(numberOfParticles))
|
2012-11-08 08:02:58 +04:00
|
|
|
{
|
2013-12-18 13:47:20 +04:00
|
|
|
ret->autorelease();
|
2012-11-08 08:02:58 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-18 13:47:20 +04:00
|
|
|
CC_SAFE_DELETE(ret);
|
2012-11-08 08:02:58 +04:00
|
|
|
}
|
2013-12-18 13:47:20 +04:00
|
|
|
return ret;
|
2012-11-08 08:02:58 +04:00
|
|
|
}
|
|
|
|
|
2013-11-16 01:14:12 +04:00
|
|
|
bool ParticleFire::initWithTotalParticles(int numberOfParticles)
|
2010-12-28 09:04:28 +03:00
|
|
|
{
|
2013-06-20 10:13:12 +04:00
|
|
|
if( ParticleSystemQuad::initWithTotalParticles(numberOfParticles) )
|
2012-04-19 10:35:52 +04:00
|
|
|
{
|
|
|
|
// duration
|
2013-07-25 10:27:46 +04:00
|
|
|
_duration = DURATION_INFINITY;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// Gravity Mode
|
2013-07-26 09:48:32 +04:00
|
|
|
this->_emitterMode = Mode::GRAVITY;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// Gravity Mode: gravity
|
2015-04-19 20:40:52 +03:00
|
|
|
this->modeA.gravity.setZero();
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// 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
|
2013-06-15 10:03:30 +04:00
|
|
|
_angle = 90;
|
|
|
|
_angleVar = 10;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// emitter position
|
2013-07-12 02:24:23 +04:00
|
|
|
Size winSize = Director::getInstance()->getWinSize();
|
2015-04-19 20:40:52 +03:00
|
|
|
this->setPosition(winSize.width/2.0f, 60.0f);
|
|
|
|
this->_posVar.set(40.0f, 20.0f);
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// life of particles
|
2013-06-15 10:03:30 +04:00
|
|
|
_life = 3;
|
|
|
|
_lifeVar = 0.25f;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
|
|
|
|
// size, in pixels
|
2013-06-15 10:03:30 +04:00
|
|
|
_startSize = 54.0f;
|
|
|
|
_startSizeVar = 10.0f;
|
2013-07-25 10:27:46 +04:00
|
|
|
_endSize = START_SIZE_EQUAL_TO_END_SIZE;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// emits per frame
|
2013-06-15 10:03:30 +04:00
|
|
|
_emissionRate = _totalParticles/_life;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// color of particles
|
2013-06-15 10:03:30 +04:00
|
|
|
_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;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
2013-07-26 02:53:24 +04:00
|
|
|
Texture2D* texture = getDefaultTexture();
|
2013-12-18 13:47:20 +04:00
|
|
|
if (texture != nullptr)
|
2012-11-08 08:02:58 +04:00
|
|
|
{
|
2013-07-26 02:53:24 +04:00
|
|
|
setTexture(texture);
|
2012-11-08 08:02:58 +04:00
|
|
|
}
|
|
|
|
|
2012-04-19 10:35:52 +04:00
|
|
|
// additive
|
2012-06-15 11:10:40 +04:00
|
|
|
this->setBlendAdditive(true);
|
2012-04-19 10:35:52 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2010-12-28 09:04:28 +03:00
|
|
|
}
|
|
|
|
//
|
|
|
|
// ParticleFireworks
|
|
|
|
//
|
2012-11-01 18:17:12 +04:00
|
|
|
|
2013-06-20 10:13:12 +04:00
|
|
|
ParticleFireworks* ParticleFireworks::create()
|
2012-11-01 18:17:12 +04:00
|
|
|
{
|
2014-08-28 03:31:57 +04:00
|
|
|
ParticleFireworks* ret = new (std::nothrow) ParticleFireworks();
|
2013-12-18 13:47:20 +04:00
|
|
|
if (ret && ret->init())
|
2012-11-01 18:17:12 +04:00
|
|
|
{
|
2013-12-18 13:47:20 +04:00
|
|
|
ret->autorelease();
|
2012-11-01 18:17:12 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-18 13:47:20 +04:00
|
|
|
CC_SAFE_DELETE(ret);
|
2012-11-01 18:17:12 +04:00
|
|
|
}
|
2013-12-18 13:47:20 +04:00
|
|
|
return ret;
|
2012-11-01 18:17:12 +04:00
|
|
|
}
|
|
|
|
|
2013-11-16 01:14:12 +04:00
|
|
|
ParticleFireworks* ParticleFireworks::createWithTotalParticles(int numberOfParticles)
|
2012-11-08 08:02:58 +04:00
|
|
|
{
|
2014-08-28 03:31:57 +04:00
|
|
|
ParticleFireworks* ret = new (std::nothrow) ParticleFireworks();
|
2013-12-18 13:47:20 +04:00
|
|
|
if (ret && ret->initWithTotalParticles(numberOfParticles))
|
2012-11-08 08:02:58 +04:00
|
|
|
{
|
2013-12-18 13:47:20 +04:00
|
|
|
ret->autorelease();
|
2012-11-08 08:02:58 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-18 13:47:20 +04:00
|
|
|
CC_SAFE_DELETE(ret);
|
2012-11-08 08:02:58 +04:00
|
|
|
}
|
2013-12-18 13:47:20 +04:00
|
|
|
return ret;
|
2012-11-08 08:02:58 +04:00
|
|
|
}
|
|
|
|
|
2013-11-16 01:14:12 +04:00
|
|
|
bool ParticleFireworks::initWithTotalParticles(int numberOfParticles)
|
2010-12-28 09:04:28 +03:00
|
|
|
{
|
2013-06-20 10:13:12 +04:00
|
|
|
if( ParticleSystemQuad::initWithTotalParticles(numberOfParticles) )
|
2012-04-19 10:35:52 +04:00
|
|
|
{
|
|
|
|
// duration
|
2013-07-25 10:27:46 +04:00
|
|
|
_duration= DURATION_INFINITY;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// Gravity Mode
|
2013-07-26 09:48:32 +04:00
|
|
|
this->_emitterMode = Mode::GRAVITY;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// Gravity Mode: gravity
|
2015-04-19 20:40:52 +03:00
|
|
|
this->modeA.gravity.set(0.0f, -90.0f);
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// Gravity Mode: radial
|
2015-04-19 20:40:52 +03:00
|
|
|
this->modeA.radialAccel = 0.0f;
|
|
|
|
this->modeA.radialAccelVar = 0.0f;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// Gravity Mode: speed of particles
|
2015-04-19 20:40:52 +03:00
|
|
|
this->modeA.speed = 180.0f;
|
|
|
|
this->modeA.speedVar = 50.0f;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// emitter position
|
2013-07-12 02:24:23 +04:00
|
|
|
Size winSize = Director::getInstance()->getWinSize();
|
2014-08-28 07:41:18 +04:00
|
|
|
this->setPosition(winSize.width/2, winSize.height/2);
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// angle
|
2015-04-19 20:40:52 +03:00
|
|
|
this->_angle= 90.0f;
|
|
|
|
this->_angleVar = 20.0f;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// life of particles
|
2013-06-15 10:03:30 +04:00
|
|
|
this->_life = 3.5f;
|
2015-04-19 20:40:52 +03:00
|
|
|
this->_lifeVar = 1.0f;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// emits per frame
|
2013-06-15 10:03:30 +04:00
|
|
|
this->_emissionRate = _totalParticles/_life;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// color of particles
|
2013-06-15 10:03:30 +04:00
|
|
|
_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;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// size, in pixels
|
2013-06-15 10:03:30 +04:00
|
|
|
_startSize = 8.0f;
|
|
|
|
_startSizeVar = 2.0f;
|
2013-07-25 10:27:46 +04:00
|
|
|
_endSize = START_SIZE_EQUAL_TO_END_SIZE;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
2013-07-26 02:53:24 +04:00
|
|
|
Texture2D* texture = getDefaultTexture();
|
2013-12-18 13:47:20 +04:00
|
|
|
if (texture != nullptr)
|
2012-11-08 08:02:58 +04:00
|
|
|
{
|
2013-07-26 02:53:24 +04:00
|
|
|
setTexture(texture);
|
2012-11-08 08:02:58 +04:00
|
|
|
}
|
2012-04-19 10:35:52 +04:00
|
|
|
// additive
|
2012-06-15 11:10:40 +04:00
|
|
|
this->setBlendAdditive(false);
|
2012-04-19 10:35:52 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2010-12-28 09:04:28 +03:00
|
|
|
}
|
|
|
|
//
|
|
|
|
// ParticleSun
|
|
|
|
//
|
2013-06-20 10:13:12 +04:00
|
|
|
ParticleSun* ParticleSun::create()
|
2012-11-01 18:17:12 +04:00
|
|
|
{
|
2014-08-28 03:31:57 +04:00
|
|
|
ParticleSun* ret = new (std::nothrow) ParticleSun();
|
2013-12-18 13:47:20 +04:00
|
|
|
if (ret && ret->init())
|
2012-11-01 18:17:12 +04:00
|
|
|
{
|
2013-12-18 13:47:20 +04:00
|
|
|
ret->autorelease();
|
2012-11-01 18:17:12 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-18 13:47:20 +04:00
|
|
|
CC_SAFE_DELETE(ret);
|
2012-11-01 18:17:12 +04:00
|
|
|
}
|
2013-12-18 13:47:20 +04:00
|
|
|
return ret;
|
2012-11-01 18:17:12 +04:00
|
|
|
}
|
|
|
|
|
2013-11-16 01:14:12 +04:00
|
|
|
ParticleSun* ParticleSun::createWithTotalParticles(int numberOfParticles)
|
2012-11-08 08:02:58 +04:00
|
|
|
{
|
2014-08-28 03:31:57 +04:00
|
|
|
ParticleSun* ret = new (std::nothrow) ParticleSun();
|
2013-12-18 13:47:20 +04:00
|
|
|
if (ret && ret->initWithTotalParticles(numberOfParticles))
|
2012-11-08 08:02:58 +04:00
|
|
|
{
|
2013-12-18 13:47:20 +04:00
|
|
|
ret->autorelease();
|
2012-11-08 08:02:58 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-18 13:47:20 +04:00
|
|
|
CC_SAFE_DELETE(ret);
|
2012-11-08 08:02:58 +04:00
|
|
|
}
|
2013-12-18 13:47:20 +04:00
|
|
|
return ret;
|
2012-11-08 08:02:58 +04:00
|
|
|
}
|
|
|
|
|
2013-11-16 01:14:12 +04:00
|
|
|
bool ParticleSun::initWithTotalParticles(int numberOfParticles)
|
2010-12-28 09:04:28 +03:00
|
|
|
{
|
2013-06-20 10:13:12 +04:00
|
|
|
if( ParticleSystemQuad::initWithTotalParticles(numberOfParticles) )
|
2012-04-19 10:35:52 +04:00
|
|
|
{
|
|
|
|
// additive
|
2012-06-15 11:10:40 +04:00
|
|
|
this->setBlendAdditive(true);
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// duration
|
2013-07-25 10:27:46 +04:00
|
|
|
_duration = DURATION_INFINITY;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// Gravity Mode
|
2013-07-26 09:48:32 +04:00
|
|
|
setEmitterMode(Mode::GRAVITY);
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// Gravity Mode: gravity
|
2014-05-14 21:07:09 +04:00
|
|
|
setGravity(Vec2(0,0));
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// Gravity mode: radial acceleration
|
2013-02-27 12:46:05 +04:00
|
|
|
setRadialAccel(0);
|
|
|
|
setRadialAccelVar(0);
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// Gravity mode: speed of particles
|
2013-02-27 12:46:05 +04:00
|
|
|
setSpeed(20);
|
|
|
|
setSpeedVar(5);
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
|
|
|
|
// angle
|
2013-06-15 10:03:30 +04:00
|
|
|
_angle = 90;
|
|
|
|
_angleVar = 360;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// emitter position
|
2013-07-12 02:24:23 +04:00
|
|
|
Size winSize = Director::getInstance()->getWinSize();
|
2014-08-28 07:41:18 +04:00
|
|
|
this->setPosition(winSize.width/2, winSize.height/2);
|
2014-05-14 21:07:09 +04:00
|
|
|
setPosVar(Vec2::ZERO);
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// life of particles
|
2013-06-15 10:03:30 +04:00
|
|
|
_life = 1;
|
|
|
|
_lifeVar = 0.5f;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// size, in pixels
|
2013-06-15 10:03:30 +04:00
|
|
|
_startSize = 30.0f;
|
|
|
|
_startSizeVar = 10.0f;
|
2013-07-25 10:27:46 +04:00
|
|
|
_endSize = START_SIZE_EQUAL_TO_END_SIZE;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// emits per seconds
|
2013-06-15 10:03:30 +04:00
|
|
|
_emissionRate = _totalParticles/_life;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// color of particles
|
2013-06-15 10:03:30 +04:00
|
|
|
_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;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
2013-07-26 02:53:24 +04:00
|
|
|
Texture2D* texture = getDefaultTexture();
|
2013-12-18 13:47:20 +04:00
|
|
|
if (texture != nullptr)
|
2012-11-08 08:02:58 +04:00
|
|
|
{
|
2013-07-26 02:53:24 +04:00
|
|
|
setTexture(texture);
|
2012-11-08 08:02:58 +04:00
|
|
|
}
|
|
|
|
|
2012-04-19 10:35:52 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2010-12-28 09:04:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// ParticleGalaxy
|
|
|
|
//
|
2012-11-01 18:17:12 +04:00
|
|
|
|
2013-06-20 10:13:12 +04:00
|
|
|
ParticleGalaxy* ParticleGalaxy::create()
|
2012-11-01 18:17:12 +04:00
|
|
|
{
|
2014-08-28 03:31:57 +04:00
|
|
|
ParticleGalaxy* ret = new (std::nothrow) ParticleGalaxy();
|
2013-12-18 13:47:20 +04:00
|
|
|
if (ret && ret->init())
|
2012-11-01 18:17:12 +04:00
|
|
|
{
|
2013-12-18 13:47:20 +04:00
|
|
|
ret->autorelease();
|
2012-11-01 18:17:12 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-18 13:47:20 +04:00
|
|
|
CC_SAFE_DELETE(ret);
|
2012-11-01 18:17:12 +04:00
|
|
|
}
|
2013-12-18 13:47:20 +04:00
|
|
|
return ret;
|
2012-11-01 18:17:12 +04:00
|
|
|
}
|
|
|
|
|
2013-11-16 01:14:12 +04:00
|
|
|
ParticleGalaxy* ParticleGalaxy::createWithTotalParticles(int numberOfParticles)
|
2012-11-08 08:02:58 +04:00
|
|
|
{
|
2014-08-28 03:31:57 +04:00
|
|
|
ParticleGalaxy* ret = new (std::nothrow) ParticleGalaxy();
|
2013-12-18 13:47:20 +04:00
|
|
|
if (ret && ret->initWithTotalParticles(numberOfParticles))
|
2012-11-08 08:02:58 +04:00
|
|
|
{
|
2013-12-18 13:47:20 +04:00
|
|
|
ret->autorelease();
|
2012-11-08 08:02:58 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-18 13:47:20 +04:00
|
|
|
CC_SAFE_DELETE(ret);
|
2012-11-08 08:02:58 +04:00
|
|
|
}
|
2013-12-18 13:47:20 +04:00
|
|
|
return ret;
|
2012-11-08 08:02:58 +04:00
|
|
|
}
|
|
|
|
|
2013-11-16 01:14:12 +04:00
|
|
|
bool ParticleGalaxy::initWithTotalParticles(int numberOfParticles)
|
2010-12-28 09:04:28 +03:00
|
|
|
{
|
2013-06-20 10:13:12 +04:00
|
|
|
if( ParticleSystemQuad::initWithTotalParticles(numberOfParticles) )
|
2012-04-19 10:35:52 +04:00
|
|
|
{
|
|
|
|
// duration
|
2013-07-25 10:27:46 +04:00
|
|
|
_duration = DURATION_INFINITY;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// Gravity Mode
|
2013-07-26 09:48:32 +04:00
|
|
|
setEmitterMode(Mode::GRAVITY);
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// Gravity Mode: gravity
|
2014-05-14 21:07:09 +04:00
|
|
|
setGravity(Vec2(0,0));
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// Gravity Mode: speed of particles
|
2013-02-27 12:46:05 +04:00
|
|
|
setSpeed(60);
|
|
|
|
setSpeedVar(10);
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// Gravity Mode: radial
|
2013-02-27 12:46:05 +04:00
|
|
|
setRadialAccel(-80);
|
|
|
|
setRadialAccelVar(0);
|
2012-04-19 10:35:52 +04:00
|
|
|
|
2012-09-17 11:02:24 +04:00
|
|
|
// Gravity Mode: tangential
|
2013-02-27 12:46:05 +04:00
|
|
|
setTangentialAccel(80);
|
|
|
|
setTangentialAccelVar(0);
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// angle
|
2013-06-15 10:03:30 +04:00
|
|
|
_angle = 90;
|
|
|
|
_angleVar = 360;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// emitter position
|
2013-07-12 02:24:23 +04:00
|
|
|
Size winSize = Director::getInstance()->getWinSize();
|
2014-08-28 07:41:18 +04:00
|
|
|
this->setPosition(winSize.width/2, winSize.height/2);
|
2014-05-14 21:07:09 +04:00
|
|
|
setPosVar(Vec2::ZERO);
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// life of particles
|
2013-06-15 10:03:30 +04:00
|
|
|
_life = 4;
|
|
|
|
_lifeVar = 1;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// size, in pixels
|
2013-06-15 10:03:30 +04:00
|
|
|
_startSize = 37.0f;
|
|
|
|
_startSizeVar = 10.0f;
|
2013-07-25 10:27:46 +04:00
|
|
|
_endSize = START_SIZE_EQUAL_TO_END_SIZE;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// emits per second
|
2013-06-15 10:03:30 +04:00
|
|
|
_emissionRate = _totalParticles/_life;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// color of particles
|
2013-06-15 10:03:30 +04:00
|
|
|
_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;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
2013-07-26 02:53:24 +04:00
|
|
|
Texture2D* texture = getDefaultTexture();
|
2013-12-18 13:47:20 +04:00
|
|
|
if (texture != nullptr)
|
2012-11-08 08:02:58 +04:00
|
|
|
{
|
2013-07-26 02:53:24 +04:00
|
|
|
setTexture(texture);
|
2012-11-08 08:02:58 +04:00
|
|
|
}
|
|
|
|
|
2012-04-19 10:35:52 +04:00
|
|
|
// additive
|
2012-06-15 11:10:40 +04:00
|
|
|
this->setBlendAdditive(true);
|
2012-04-19 10:35:52 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2010-12-28 09:04:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// ParticleFlower
|
|
|
|
//
|
2012-11-01 18:17:12 +04:00
|
|
|
|
2013-06-20 10:13:12 +04:00
|
|
|
ParticleFlower* ParticleFlower::create()
|
2012-11-01 18:17:12 +04:00
|
|
|
{
|
2014-08-28 03:31:57 +04:00
|
|
|
ParticleFlower* ret = new (std::nothrow) ParticleFlower();
|
2013-12-18 13:47:20 +04:00
|
|
|
if (ret && ret->init())
|
2012-11-01 18:17:12 +04:00
|
|
|
{
|
2013-12-18 13:47:20 +04:00
|
|
|
ret->autorelease();
|
2012-11-01 18:17:12 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-18 13:47:20 +04:00
|
|
|
CC_SAFE_DELETE(ret);
|
2012-11-01 18:17:12 +04:00
|
|
|
}
|
2013-12-18 13:47:20 +04:00
|
|
|
return ret;
|
2012-11-01 18:17:12 +04:00
|
|
|
}
|
|
|
|
|
2013-11-16 01:14:12 +04:00
|
|
|
ParticleFlower* ParticleFlower::createWithTotalParticles(int numberOfParticles)
|
2012-11-08 08:02:58 +04:00
|
|
|
{
|
2014-08-28 03:31:57 +04:00
|
|
|
ParticleFlower* ret = new (std::nothrow) ParticleFlower();
|
2013-12-18 13:47:20 +04:00
|
|
|
if (ret && ret->initWithTotalParticles(numberOfParticles))
|
2012-11-08 08:02:58 +04:00
|
|
|
{
|
2013-12-18 13:47:20 +04:00
|
|
|
ret->autorelease();
|
2012-11-08 08:02:58 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-18 13:47:20 +04:00
|
|
|
CC_SAFE_DELETE(ret);
|
2012-11-08 08:02:58 +04:00
|
|
|
}
|
2013-12-18 13:47:20 +04:00
|
|
|
return ret;
|
2012-11-08 08:02:58 +04:00
|
|
|
}
|
|
|
|
|
2013-11-16 01:14:12 +04:00
|
|
|
bool ParticleFlower::initWithTotalParticles(int numberOfParticles)
|
2010-12-28 09:04:28 +03:00
|
|
|
{
|
2013-06-20 10:13:12 +04:00
|
|
|
if( ParticleSystemQuad::initWithTotalParticles(numberOfParticles) )
|
2012-04-19 10:35:52 +04:00
|
|
|
{
|
|
|
|
// duration
|
2013-07-25 10:27:46 +04:00
|
|
|
_duration = DURATION_INFINITY;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// Gravity Mode
|
2013-07-26 09:48:32 +04:00
|
|
|
setEmitterMode(Mode::GRAVITY);
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// Gravity Mode: gravity
|
2014-05-14 21:07:09 +04:00
|
|
|
setGravity(Vec2(0,0));
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// Gravity Mode: speed of particles
|
2013-02-27 12:46:05 +04:00
|
|
|
setSpeed(80);
|
|
|
|
setSpeedVar(10);
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// Gravity Mode: radial
|
2013-02-27 12:46:05 +04:00
|
|
|
setRadialAccel(-60);
|
|
|
|
setRadialAccelVar(0);
|
2012-04-19 10:35:52 +04:00
|
|
|
|
2012-09-17 11:02:24 +04:00
|
|
|
// Gravity Mode: tangential
|
2013-02-27 12:46:05 +04:00
|
|
|
setTangentialAccel(15);
|
|
|
|
setTangentialAccelVar(0);
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// angle
|
2013-06-15 10:03:30 +04:00
|
|
|
_angle = 90;
|
|
|
|
_angleVar = 360;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// emitter position
|
2013-07-12 02:24:23 +04:00
|
|
|
Size winSize = Director::getInstance()->getWinSize();
|
2014-08-28 07:41:18 +04:00
|
|
|
this->setPosition(winSize.width/2, winSize.height/2);
|
2014-05-14 21:07:09 +04:00
|
|
|
setPosVar(Vec2::ZERO);
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// life of particles
|
2013-06-15 10:03:30 +04:00
|
|
|
_life = 4;
|
|
|
|
_lifeVar = 1;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// size, in pixels
|
2013-06-15 10:03:30 +04:00
|
|
|
_startSize = 30.0f;
|
|
|
|
_startSizeVar = 10.0f;
|
2013-07-25 10:27:46 +04:00
|
|
|
_endSize = START_SIZE_EQUAL_TO_END_SIZE;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// emits per second
|
2013-06-15 10:03:30 +04:00
|
|
|
_emissionRate = _totalParticles/_life;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// color of particles
|
2013-06-15 10:03:30 +04:00
|
|
|
_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;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
2013-07-26 02:53:24 +04:00
|
|
|
Texture2D* texture = getDefaultTexture();
|
2013-12-18 13:47:20 +04:00
|
|
|
if (texture != nullptr)
|
2012-11-08 08:02:58 +04:00
|
|
|
{
|
2013-07-26 02:53:24 +04:00
|
|
|
setTexture(texture);
|
2012-11-08 08:02:58 +04:00
|
|
|
}
|
|
|
|
|
2012-04-19 10:35:52 +04:00
|
|
|
// additive
|
2012-06-15 11:10:40 +04:00
|
|
|
this->setBlendAdditive(true);
|
2012-04-19 10:35:52 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2010-12-28 09:04:28 +03:00
|
|
|
}
|
|
|
|
//
|
|
|
|
// ParticleMeteor
|
|
|
|
//
|
2012-11-01 18:17:12 +04:00
|
|
|
|
2013-06-20 10:13:12 +04:00
|
|
|
ParticleMeteor * ParticleMeteor::create()
|
2012-11-01 18:17:12 +04:00
|
|
|
{
|
2014-08-28 03:31:57 +04:00
|
|
|
ParticleMeteor *ret = new (std::nothrow) ParticleMeteor();
|
2013-12-18 13:47:20 +04:00
|
|
|
if (ret && ret->init())
|
2012-11-01 18:17:12 +04:00
|
|
|
{
|
2013-12-18 13:47:20 +04:00
|
|
|
ret->autorelease();
|
2012-11-01 18:17:12 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-18 13:47:20 +04:00
|
|
|
CC_SAFE_DELETE(ret);
|
2012-11-01 18:17:12 +04:00
|
|
|
}
|
2013-12-18 13:47:20 +04:00
|
|
|
return ret;
|
2012-11-01 18:17:12 +04:00
|
|
|
}
|
|
|
|
|
2013-11-16 01:14:12 +04:00
|
|
|
ParticleMeteor* ParticleMeteor::createWithTotalParticles(int numberOfParticles)
|
2012-11-08 08:02:58 +04:00
|
|
|
{
|
2014-08-28 03:31:57 +04:00
|
|
|
ParticleMeteor* ret = new (std::nothrow) ParticleMeteor();
|
2013-12-18 13:47:20 +04:00
|
|
|
if (ret && ret->initWithTotalParticles(numberOfParticles))
|
2012-11-08 08:02:58 +04:00
|
|
|
{
|
2013-12-18 13:47:20 +04:00
|
|
|
ret->autorelease();
|
2012-11-08 08:02:58 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-18 13:47:20 +04:00
|
|
|
CC_SAFE_DELETE(ret);
|
2012-11-08 08:02:58 +04:00
|
|
|
}
|
2013-12-18 13:47:20 +04:00
|
|
|
return ret;
|
2012-11-08 08:02:58 +04:00
|
|
|
}
|
|
|
|
|
2013-11-16 01:14:12 +04:00
|
|
|
bool ParticleMeteor::initWithTotalParticles(int numberOfParticles)
|
2010-12-28 09:04:28 +03:00
|
|
|
{
|
2013-06-20 10:13:12 +04:00
|
|
|
if( ParticleSystemQuad::initWithTotalParticles(numberOfParticles) )
|
2012-04-19 10:35:52 +04:00
|
|
|
{
|
|
|
|
// duration
|
2013-07-25 10:27:46 +04:00
|
|
|
_duration = DURATION_INFINITY;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// Gravity Mode
|
2013-07-26 09:48:32 +04:00
|
|
|
setEmitterMode(Mode::GRAVITY);
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// Gravity Mode: gravity
|
2014-05-14 21:07:09 +04:00
|
|
|
setGravity(Vec2(-200,200));
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// Gravity Mode: speed of particles
|
2013-02-27 12:46:05 +04:00
|
|
|
setSpeed(15);
|
|
|
|
setSpeedVar(5);
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// Gravity Mode: radial
|
2013-02-27 12:46:05 +04:00
|
|
|
setRadialAccel(0);
|
|
|
|
setRadialAccelVar(0);
|
2012-04-19 10:35:52 +04:00
|
|
|
|
2012-09-17 11:02:24 +04:00
|
|
|
// Gravity Mode: tangential
|
2013-02-27 12:46:05 +04:00
|
|
|
setTangentialAccel(0);
|
|
|
|
setTangentialAccelVar(0);
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// angle
|
2013-06-15 10:03:30 +04:00
|
|
|
_angle = 90;
|
|
|
|
_angleVar = 360;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// emitter position
|
2013-07-12 02:24:23 +04:00
|
|
|
Size winSize = Director::getInstance()->getWinSize();
|
2014-08-28 07:41:18 +04:00
|
|
|
this->setPosition(winSize.width/2, winSize.height/2);
|
2014-05-14 21:07:09 +04:00
|
|
|
setPosVar(Vec2::ZERO);
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// life of particles
|
2013-06-15 10:03:30 +04:00
|
|
|
_life = 2;
|
|
|
|
_lifeVar = 1;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// size, in pixels
|
2013-06-15 10:03:30 +04:00
|
|
|
_startSize = 60.0f;
|
|
|
|
_startSizeVar = 10.0f;
|
2013-07-25 10:27:46 +04:00
|
|
|
_endSize = START_SIZE_EQUAL_TO_END_SIZE;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// emits per second
|
2013-06-15 10:03:30 +04:00
|
|
|
_emissionRate = _totalParticles/_life;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// color of particles
|
2013-06-15 10:03:30 +04:00
|
|
|
_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;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
2013-07-26 02:53:24 +04:00
|
|
|
Texture2D* texture = getDefaultTexture();
|
2013-12-18 13:47:20 +04:00
|
|
|
if (texture != nullptr)
|
2012-11-08 08:02:58 +04:00
|
|
|
{
|
2013-07-26 02:53:24 +04:00
|
|
|
setTexture(texture);
|
2012-11-08 08:02:58 +04:00
|
|
|
}
|
|
|
|
|
2012-04-19 10:35:52 +04:00
|
|
|
// additive
|
2012-06-15 11:10:40 +04:00
|
|
|
this->setBlendAdditive(true);
|
2012-04-19 10:35:52 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2010-12-28 09:04:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// ParticleSpiral
|
|
|
|
//
|
2012-11-01 18:17:12 +04:00
|
|
|
|
2013-06-20 10:13:12 +04:00
|
|
|
ParticleSpiral* ParticleSpiral::create()
|
2012-11-01 18:17:12 +04:00
|
|
|
{
|
2014-08-28 03:31:57 +04:00
|
|
|
ParticleSpiral* ret = new (std::nothrow) ParticleSpiral();
|
2013-12-18 13:47:20 +04:00
|
|
|
if (ret && ret->init())
|
2012-11-01 18:17:12 +04:00
|
|
|
{
|
2013-12-18 13:47:20 +04:00
|
|
|
ret->autorelease();
|
2012-11-01 18:17:12 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-18 13:47:20 +04:00
|
|
|
CC_SAFE_DELETE(ret);
|
2012-11-01 18:17:12 +04:00
|
|
|
}
|
2013-12-18 13:47:20 +04:00
|
|
|
return ret;
|
2012-11-01 18:17:12 +04:00
|
|
|
}
|
|
|
|
|
2013-11-16 01:14:12 +04:00
|
|
|
ParticleSpiral* ParticleSpiral::createWithTotalParticles(int numberOfParticles)
|
2012-11-08 08:02:58 +04:00
|
|
|
{
|
2014-08-28 03:31:57 +04:00
|
|
|
ParticleSpiral* ret = new (std::nothrow) ParticleSpiral();
|
2013-12-18 13:47:20 +04:00
|
|
|
if (ret && ret->initWithTotalParticles(numberOfParticles))
|
2012-11-08 08:02:58 +04:00
|
|
|
{
|
2013-12-18 13:47:20 +04:00
|
|
|
ret->autorelease();
|
2012-11-08 08:02:58 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-18 13:47:20 +04:00
|
|
|
CC_SAFE_DELETE(ret);
|
2012-11-08 08:02:58 +04:00
|
|
|
}
|
2013-12-18 13:47:20 +04:00
|
|
|
return ret;
|
2012-11-08 08:02:58 +04:00
|
|
|
}
|
|
|
|
|
2013-11-16 01:14:12 +04:00
|
|
|
bool ParticleSpiral::initWithTotalParticles(int numberOfParticles)
|
2010-12-28 09:04:28 +03:00
|
|
|
{
|
2013-06-20 10:13:12 +04:00
|
|
|
if( ParticleSystemQuad::initWithTotalParticles(numberOfParticles) )
|
2012-04-19 10:35:52 +04:00
|
|
|
{
|
|
|
|
// duration
|
2013-07-25 10:27:46 +04:00
|
|
|
_duration = DURATION_INFINITY;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// Gravity Mode
|
2013-07-26 09:48:32 +04:00
|
|
|
setEmitterMode(Mode::GRAVITY);
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// Gravity Mode: gravity
|
2014-05-14 21:07:09 +04:00
|
|
|
setGravity(Vec2(0,0));
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// Gravity Mode: speed of particles
|
2013-02-27 12:46:05 +04:00
|
|
|
setSpeed(150);
|
|
|
|
setSpeedVar(0);
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// Gravity Mode: radial
|
2013-02-27 12:46:05 +04:00
|
|
|
setRadialAccel(-380);
|
|
|
|
setRadialAccelVar(0);
|
2012-04-19 10:35:52 +04:00
|
|
|
|
2012-09-17 11:02:24 +04:00
|
|
|
// Gravity Mode: tangential
|
2013-02-27 12:46:05 +04:00
|
|
|
setTangentialAccel(45);
|
|
|
|
setTangentialAccelVar(0);
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// angle
|
2013-06-15 10:03:30 +04:00
|
|
|
_angle = 90;
|
|
|
|
_angleVar = 0;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// emitter position
|
2013-07-12 02:24:23 +04:00
|
|
|
Size winSize = Director::getInstance()->getWinSize();
|
2014-08-28 07:41:18 +04:00
|
|
|
this->setPosition(winSize.width/2, winSize.height/2);
|
2014-05-14 21:07:09 +04:00
|
|
|
setPosVar(Vec2::ZERO);
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// life of particles
|
2013-06-15 10:03:30 +04:00
|
|
|
_life = 12;
|
|
|
|
_lifeVar = 0;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// size, in pixels
|
2013-06-15 10:03:30 +04:00
|
|
|
_startSize = 20.0f;
|
|
|
|
_startSizeVar = 0.0f;
|
2013-07-25 10:27:46 +04:00
|
|
|
_endSize = START_SIZE_EQUAL_TO_END_SIZE;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// emits per second
|
2013-06-15 10:03:30 +04:00
|
|
|
_emissionRate = _totalParticles/_life;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// color of particles
|
2013-06-15 10:03:30 +04:00
|
|
|
_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;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
2013-07-26 02:53:24 +04:00
|
|
|
Texture2D* texture = getDefaultTexture();
|
2013-12-18 13:47:20 +04:00
|
|
|
if (texture != nullptr)
|
2012-11-08 08:02:58 +04:00
|
|
|
{
|
2013-07-26 02:53:24 +04:00
|
|
|
setTexture(texture);
|
2012-11-08 08:02:58 +04:00
|
|
|
}
|
|
|
|
|
2012-04-19 10:35:52 +04:00
|
|
|
// additive
|
2012-06-15 11:10:40 +04:00
|
|
|
this->setBlendAdditive(false);
|
2012-04-19 10:35:52 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2010-12-28 09:04:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// ParticleExplosion
|
|
|
|
//
|
2012-11-01 18:17:12 +04:00
|
|
|
|
2013-06-20 10:13:12 +04:00
|
|
|
ParticleExplosion* ParticleExplosion::create()
|
2012-11-01 18:17:12 +04:00
|
|
|
{
|
2014-08-28 03:31:57 +04:00
|
|
|
ParticleExplosion* ret = new (std::nothrow) ParticleExplosion();
|
2013-12-18 13:47:20 +04:00
|
|
|
if (ret && ret->init())
|
2012-11-01 18:17:12 +04:00
|
|
|
{
|
2013-12-18 13:47:20 +04:00
|
|
|
ret->autorelease();
|
2012-11-01 18:17:12 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-18 13:47:20 +04:00
|
|
|
CC_SAFE_DELETE(ret);
|
2012-11-01 18:17:12 +04:00
|
|
|
}
|
2013-12-18 13:47:20 +04:00
|
|
|
return ret;
|
2012-11-01 18:17:12 +04:00
|
|
|
}
|
|
|
|
|
2013-11-16 01:14:12 +04:00
|
|
|
ParticleExplosion* ParticleExplosion::createWithTotalParticles(int numberOfParticles)
|
2012-11-08 08:02:58 +04:00
|
|
|
{
|
2014-08-28 03:31:57 +04:00
|
|
|
ParticleExplosion* ret = new (std::nothrow) ParticleExplosion();
|
2013-12-18 13:47:20 +04:00
|
|
|
if (ret && ret->initWithTotalParticles(numberOfParticles))
|
2012-11-08 08:02:58 +04:00
|
|
|
{
|
2013-12-18 13:47:20 +04:00
|
|
|
ret->autorelease();
|
2012-11-08 08:02:58 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-18 13:47:20 +04:00
|
|
|
CC_SAFE_DELETE(ret);
|
2012-11-08 08:02:58 +04:00
|
|
|
}
|
2013-12-18 13:47:20 +04:00
|
|
|
return ret;
|
2012-11-08 08:02:58 +04:00
|
|
|
}
|
|
|
|
|
2013-11-16 01:14:12 +04:00
|
|
|
bool ParticleExplosion::initWithTotalParticles(int numberOfParticles)
|
2010-12-28 09:04:28 +03:00
|
|
|
{
|
2013-06-20 10:13:12 +04:00
|
|
|
if( ParticleSystemQuad::initWithTotalParticles(numberOfParticles) )
|
2012-04-19 10:35:52 +04:00
|
|
|
{
|
|
|
|
// duration
|
2013-06-15 10:03:30 +04:00
|
|
|
_duration = 0.1f;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
2013-07-26 09:48:32 +04:00
|
|
|
setEmitterMode(Mode::GRAVITY);
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// Gravity Mode: gravity
|
2014-05-14 21:07:09 +04:00
|
|
|
setGravity(Vec2(0,0));
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// Gravity Mode: speed of particles
|
2013-02-27 12:46:05 +04:00
|
|
|
setSpeed(70);
|
|
|
|
setSpeedVar(40);
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// Gravity Mode: radial
|
2013-02-27 12:46:05 +04:00
|
|
|
setRadialAccel(0);
|
|
|
|
setRadialAccelVar(0);
|
2012-04-19 10:35:52 +04:00
|
|
|
|
2012-09-17 11:02:24 +04:00
|
|
|
// Gravity Mode: tangential
|
2013-02-27 12:46:05 +04:00
|
|
|
setTangentialAccel(0);
|
|
|
|
setTangentialAccelVar(0);
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// angle
|
2013-06-15 10:03:30 +04:00
|
|
|
_angle = 90;
|
|
|
|
_angleVar = 360;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// emitter position
|
2013-07-12 02:24:23 +04:00
|
|
|
Size winSize = Director::getInstance()->getWinSize();
|
2014-08-28 07:41:18 +04:00
|
|
|
this->setPosition(winSize.width/2, winSize.height/2);
|
2014-05-14 21:07:09 +04:00
|
|
|
setPosVar(Vec2::ZERO);
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// life of particles
|
2013-06-15 10:03:30 +04:00
|
|
|
_life = 5.0f;
|
|
|
|
_lifeVar = 2;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// size, in pixels
|
2013-06-15 10:03:30 +04:00
|
|
|
_startSize = 15.0f;
|
|
|
|
_startSizeVar = 10.0f;
|
2013-07-25 10:27:46 +04:00
|
|
|
_endSize = START_SIZE_EQUAL_TO_END_SIZE;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// emits per second
|
2013-06-15 10:03:30 +04:00
|
|
|
_emissionRate = _totalParticles/_duration;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// color of particles
|
2013-06-15 10:03:30 +04:00
|
|
|
_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;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
2013-07-26 02:53:24 +04:00
|
|
|
Texture2D* texture = getDefaultTexture();
|
2013-12-18 13:47:20 +04:00
|
|
|
if (texture != nullptr)
|
2012-11-08 08:02:58 +04:00
|
|
|
{
|
2013-07-26 02:53:24 +04:00
|
|
|
setTexture(texture);
|
2012-11-08 08:02:58 +04:00
|
|
|
}
|
|
|
|
|
2012-04-19 10:35:52 +04:00
|
|
|
// additive
|
2012-06-15 11:10:40 +04:00
|
|
|
this->setBlendAdditive(false);
|
2012-04-19 10:35:52 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2010-12-28 09:04:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// ParticleSmoke
|
|
|
|
//
|
2012-11-01 18:17:12 +04:00
|
|
|
|
2013-06-20 10:13:12 +04:00
|
|
|
ParticleSmoke* ParticleSmoke::create()
|
2012-11-01 18:17:12 +04:00
|
|
|
{
|
2014-08-28 03:31:57 +04:00
|
|
|
ParticleSmoke* ret = new (std::nothrow) ParticleSmoke();
|
2013-12-18 13:47:20 +04:00
|
|
|
if (ret && ret->init())
|
2012-11-01 18:17:12 +04:00
|
|
|
{
|
2013-12-18 13:47:20 +04:00
|
|
|
ret->autorelease();
|
2012-11-01 18:17:12 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-18 13:47:20 +04:00
|
|
|
CC_SAFE_DELETE(ret);
|
2012-11-01 18:17:12 +04:00
|
|
|
}
|
2013-12-18 13:47:20 +04:00
|
|
|
return ret;
|
2012-11-01 18:17:12 +04:00
|
|
|
}
|
|
|
|
|
2013-11-16 01:14:12 +04:00
|
|
|
ParticleSmoke* ParticleSmoke::createWithTotalParticles(int numberOfParticles)
|
2012-11-08 08:02:58 +04:00
|
|
|
{
|
2014-08-28 03:31:57 +04:00
|
|
|
ParticleSmoke* ret = new (std::nothrow) ParticleSmoke();
|
2013-12-18 13:47:20 +04:00
|
|
|
if (ret && ret->initWithTotalParticles(numberOfParticles))
|
2012-11-08 08:02:58 +04:00
|
|
|
{
|
2013-12-18 13:47:20 +04:00
|
|
|
ret->autorelease();
|
2012-11-08 08:02:58 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-18 13:47:20 +04:00
|
|
|
CC_SAFE_DELETE(ret);
|
2012-11-08 08:02:58 +04:00
|
|
|
}
|
2013-12-18 13:47:20 +04:00
|
|
|
return ret;
|
2012-11-08 08:02:58 +04:00
|
|
|
}
|
|
|
|
|
2013-11-16 01:14:12 +04:00
|
|
|
bool ParticleSmoke::initWithTotalParticles(int numberOfParticles)
|
2010-12-28 09:04:28 +03:00
|
|
|
{
|
2013-06-20 10:13:12 +04:00
|
|
|
if( ParticleSystemQuad::initWithTotalParticles(numberOfParticles) )
|
2012-04-19 10:35:52 +04:00
|
|
|
{
|
|
|
|
// duration
|
2013-07-25 10:27:46 +04:00
|
|
|
_duration = DURATION_INFINITY;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// Emitter mode: Gravity Mode
|
2013-07-26 09:48:32 +04:00
|
|
|
setEmitterMode(Mode::GRAVITY);
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// Gravity Mode: gravity
|
2014-05-14 21:07:09 +04:00
|
|
|
setGravity(Vec2(0,0));
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// Gravity Mode: radial acceleration
|
2013-02-27 12:46:05 +04:00
|
|
|
setRadialAccel(0);
|
|
|
|
setRadialAccelVar(0);
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// Gravity Mode: speed of particles
|
2013-02-27 12:46:05 +04:00
|
|
|
setSpeed(25);
|
|
|
|
setSpeedVar(10);
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// angle
|
2013-06-15 10:03:30 +04:00
|
|
|
_angle = 90;
|
|
|
|
_angleVar = 5;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// emitter position
|
2013-07-12 02:24:23 +04:00
|
|
|
Size winSize = Director::getInstance()->getWinSize();
|
2014-08-28 07:41:18 +04:00
|
|
|
this->setPosition(winSize.width/2, 0);
|
2014-05-14 21:07:09 +04:00
|
|
|
setPosVar(Vec2(20, 0));
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// life of particles
|
2013-06-15 10:03:30 +04:00
|
|
|
_life = 4;
|
|
|
|
_lifeVar = 1;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// size, in pixels
|
2013-06-15 10:03:30 +04:00
|
|
|
_startSize = 60.0f;
|
|
|
|
_startSizeVar = 10.0f;
|
2013-07-25 10:27:46 +04:00
|
|
|
_endSize = START_SIZE_EQUAL_TO_END_SIZE;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// emits per frame
|
2013-06-15 10:03:30 +04:00
|
|
|
_emissionRate = _totalParticles/_life;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// color of particles
|
2013-06-15 10:03:30 +04:00
|
|
|
_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;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
2013-07-26 02:53:24 +04:00
|
|
|
Texture2D* texture = getDefaultTexture();
|
2013-12-18 13:47:20 +04:00
|
|
|
if (texture != nullptr)
|
2012-11-08 08:02:58 +04:00
|
|
|
{
|
2013-07-26 02:53:24 +04:00
|
|
|
setTexture(texture);
|
2012-11-08 08:02:58 +04:00
|
|
|
}
|
|
|
|
|
2012-04-19 10:35:52 +04:00
|
|
|
// additive
|
2012-06-15 11:10:40 +04:00
|
|
|
this->setBlendAdditive(false);
|
2012-04-19 10:35:52 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2010-12-28 09:04:28 +03:00
|
|
|
}
|
2012-11-01 18:17:12 +04:00
|
|
|
|
2010-12-28 09:04:28 +03:00
|
|
|
//
|
2013-06-20 10:13:12 +04:00
|
|
|
// ParticleSnow
|
2010-12-28 09:04:28 +03:00
|
|
|
//
|
2012-11-01 18:17:12 +04:00
|
|
|
|
2013-06-20 10:13:12 +04:00
|
|
|
ParticleSnow* ParticleSnow::create()
|
2012-11-01 18:17:12 +04:00
|
|
|
{
|
2014-08-28 03:31:57 +04:00
|
|
|
ParticleSnow* ret = new (std::nothrow) ParticleSnow();
|
2013-12-18 13:47:20 +04:00
|
|
|
if (ret && ret->init())
|
2012-11-01 18:17:12 +04:00
|
|
|
{
|
2013-12-18 13:47:20 +04:00
|
|
|
ret->autorelease();
|
2012-11-01 18:17:12 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-18 13:47:20 +04:00
|
|
|
CC_SAFE_DELETE(ret);
|
2012-11-01 18:17:12 +04:00
|
|
|
}
|
2013-12-18 13:47:20 +04:00
|
|
|
return ret;
|
2012-11-01 18:17:12 +04:00
|
|
|
}
|
|
|
|
|
2013-11-16 01:14:12 +04:00
|
|
|
ParticleSnow* ParticleSnow::createWithTotalParticles(int numberOfParticles)
|
2012-11-08 08:02:58 +04:00
|
|
|
{
|
2014-08-28 03:31:57 +04:00
|
|
|
ParticleSnow* ret = new (std::nothrow) ParticleSnow();
|
2013-12-18 13:47:20 +04:00
|
|
|
if (ret && ret->initWithTotalParticles(numberOfParticles))
|
2012-11-08 08:02:58 +04:00
|
|
|
{
|
2013-12-18 13:47:20 +04:00
|
|
|
ret->autorelease();
|
2012-11-08 08:02:58 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-18 13:47:20 +04:00
|
|
|
CC_SAFE_DELETE(ret);
|
2012-11-08 08:02:58 +04:00
|
|
|
}
|
2013-12-18 13:47:20 +04:00
|
|
|
return ret;
|
2012-11-08 08:02:58 +04:00
|
|
|
}
|
|
|
|
|
2013-11-16 01:14:12 +04:00
|
|
|
bool ParticleSnow::initWithTotalParticles(int numberOfParticles)
|
2010-12-28 09:04:28 +03:00
|
|
|
{
|
2013-06-20 10:13:12 +04:00
|
|
|
if( ParticleSystemQuad::initWithTotalParticles(numberOfParticles) )
|
2012-04-19 10:35:52 +04:00
|
|
|
{
|
|
|
|
// duration
|
2013-07-25 10:27:46 +04:00
|
|
|
_duration = DURATION_INFINITY;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// set gravity mode.
|
2013-07-26 09:48:32 +04:00
|
|
|
setEmitterMode(Mode::GRAVITY);
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// Gravity Mode: gravity
|
2014-05-14 21:07:09 +04:00
|
|
|
setGravity(Vec2(0,-1));
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// Gravity Mode: speed of particles
|
2013-02-27 12:46:05 +04:00
|
|
|
setSpeed(5);
|
|
|
|
setSpeedVar(1);
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// Gravity Mode: radial
|
2013-02-27 12:46:05 +04:00
|
|
|
setRadialAccel(0);
|
|
|
|
setRadialAccelVar(1);
|
2012-04-19 10:35:52 +04:00
|
|
|
|
2012-09-17 11:02:24 +04:00
|
|
|
// Gravity mode: tangential
|
2013-02-27 12:46:05 +04:00
|
|
|
setTangentialAccel(0);
|
|
|
|
setTangentialAccelVar(1);
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// emitter position
|
2013-07-12 02:24:23 +04:00
|
|
|
Size winSize = Director::getInstance()->getWinSize();
|
2014-08-28 07:41:18 +04:00
|
|
|
this->setPosition(winSize.width/2, winSize.height + 10);
|
2014-05-14 21:07:09 +04:00
|
|
|
setPosVar(Vec2(winSize.width/2, 0));
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// angle
|
2013-06-15 10:03:30 +04:00
|
|
|
_angle = -90;
|
|
|
|
_angleVar = 5;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// life of particles
|
2013-06-15 10:03:30 +04:00
|
|
|
_life = 45;
|
|
|
|
_lifeVar = 15;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// size, in pixels
|
2013-06-15 10:03:30 +04:00
|
|
|
_startSize = 10.0f;
|
|
|
|
_startSizeVar = 5.0f;
|
2013-07-25 10:27:46 +04:00
|
|
|
_endSize = START_SIZE_EQUAL_TO_END_SIZE;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// emits per second
|
2013-06-15 10:03:30 +04:00
|
|
|
_emissionRate = 10;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// color of particles
|
2013-06-15 10:03:30 +04:00
|
|
|
_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;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
2013-07-26 02:53:24 +04:00
|
|
|
Texture2D* texture = getDefaultTexture();
|
2013-12-18 13:47:20 +04:00
|
|
|
if (texture != nullptr)
|
2012-11-08 08:02:58 +04:00
|
|
|
{
|
2013-07-26 02:53:24 +04:00
|
|
|
setTexture(texture);
|
2012-11-08 08:02:58 +04:00
|
|
|
}
|
|
|
|
|
2012-04-19 10:35:52 +04:00
|
|
|
// additive
|
2012-06-15 11:10:40 +04:00
|
|
|
this->setBlendAdditive(false);
|
2012-04-19 10:35:52 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2010-12-28 09:04:28 +03:00
|
|
|
}
|
|
|
|
//
|
2013-06-20 10:13:12 +04:00
|
|
|
// ParticleRain
|
2010-12-28 09:04:28 +03:00
|
|
|
//
|
2012-11-01 18:17:12 +04:00
|
|
|
|
2013-06-20 10:13:12 +04:00
|
|
|
ParticleRain* ParticleRain::create()
|
2012-11-01 18:17:12 +04:00
|
|
|
{
|
2014-08-28 03:31:57 +04:00
|
|
|
ParticleRain* ret = new (std::nothrow) ParticleRain();
|
2013-12-18 13:47:20 +04:00
|
|
|
if (ret && ret->init())
|
2012-11-01 18:17:12 +04:00
|
|
|
{
|
2013-12-18 13:47:20 +04:00
|
|
|
ret->autorelease();
|
2012-11-01 18:17:12 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-18 13:47:20 +04:00
|
|
|
CC_SAFE_DELETE(ret);
|
2012-11-01 18:17:12 +04:00
|
|
|
}
|
2013-12-18 13:47:20 +04:00
|
|
|
return ret;
|
2012-11-01 18:17:12 +04:00
|
|
|
}
|
|
|
|
|
2013-11-16 01:14:12 +04:00
|
|
|
ParticleRain* ParticleRain::createWithTotalParticles(int numberOfParticles)
|
2012-11-08 08:02:58 +04:00
|
|
|
{
|
2014-08-28 03:31:57 +04:00
|
|
|
ParticleRain* ret = new (std::nothrow) ParticleRain();
|
2013-12-18 13:47:20 +04:00
|
|
|
if (ret && ret->initWithTotalParticles(numberOfParticles))
|
2012-11-08 08:02:58 +04:00
|
|
|
{
|
2013-12-18 13:47:20 +04:00
|
|
|
ret->autorelease();
|
2012-11-08 08:02:58 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-12-18 13:47:20 +04:00
|
|
|
CC_SAFE_DELETE(ret);
|
2012-11-08 08:02:58 +04:00
|
|
|
}
|
2013-12-18 13:47:20 +04:00
|
|
|
return ret;
|
2012-11-08 08:02:58 +04:00
|
|
|
}
|
|
|
|
|
2013-11-16 01:14:12 +04:00
|
|
|
bool ParticleRain::initWithTotalParticles(int numberOfParticles)
|
2010-12-28 09:04:28 +03:00
|
|
|
{
|
2013-06-20 10:13:12 +04:00
|
|
|
if( ParticleSystemQuad::initWithTotalParticles(numberOfParticles) )
|
2012-04-19 10:35:52 +04:00
|
|
|
{
|
|
|
|
// duration
|
2013-07-25 10:27:46 +04:00
|
|
|
_duration = DURATION_INFINITY;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
2013-07-26 09:48:32 +04:00
|
|
|
setEmitterMode(Mode::GRAVITY);
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// Gravity Mode: gravity
|
2014-05-14 21:07:09 +04:00
|
|
|
setGravity(Vec2(10,-10));
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// Gravity Mode: radial
|
2013-02-27 12:46:05 +04:00
|
|
|
setRadialAccel(0);
|
|
|
|
setRadialAccelVar(1);
|
2012-04-19 10:35:52 +04:00
|
|
|
|
2012-09-17 11:02:24 +04:00
|
|
|
// Gravity Mode: tangential
|
2013-02-27 12:46:05 +04:00
|
|
|
setTangentialAccel(0);
|
|
|
|
setTangentialAccelVar(1);
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// Gravity Mode: speed of particles
|
2013-02-27 12:46:05 +04:00
|
|
|
setSpeed(130);
|
|
|
|
setSpeedVar(30);
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// angle
|
2013-06-15 10:03:30 +04:00
|
|
|
_angle = -90;
|
|
|
|
_angleVar = 5;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
|
|
|
|
// emitter position
|
2013-07-12 02:24:23 +04:00
|
|
|
Size winSize = Director::getInstance()->getWinSize();
|
2014-08-28 07:41:18 +04:00
|
|
|
this->setPosition(winSize.width/2, winSize.height);
|
2014-05-14 21:07:09 +04:00
|
|
|
setPosVar(Vec2(winSize.width/2, 0));
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// life of particles
|
2013-06-15 10:03:30 +04:00
|
|
|
_life = 4.5f;
|
|
|
|
_lifeVar = 0;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// size, in pixels
|
2013-06-15 10:03:30 +04:00
|
|
|
_startSize = 4.0f;
|
|
|
|
_startSizeVar = 2.0f;
|
2013-07-25 10:27:46 +04:00
|
|
|
_endSize = START_SIZE_EQUAL_TO_END_SIZE;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// emits per second
|
2013-06-15 10:03:30 +04:00
|
|
|
_emissionRate = 20;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
|
|
|
// color of particles
|
2013-06-15 10:03:30 +04:00
|
|
|
_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;
|
2012-04-19 10:35:52 +04:00
|
|
|
|
2013-07-26 02:53:24 +04:00
|
|
|
Texture2D* texture = getDefaultTexture();
|
2013-12-18 13:47:20 +04:00
|
|
|
if (texture != nullptr)
|
2012-11-08 08:02:58 +04:00
|
|
|
{
|
2013-07-26 02:53:24 +04:00
|
|
|
setTexture(texture);
|
2012-11-08 08:02:58 +04:00
|
|
|
}
|
|
|
|
|
2012-04-19 10:35:52 +04:00
|
|
|
// additive
|
2012-06-15 11:10:40 +04:00
|
|
|
this->setBlendAdditive(false);
|
2012-04-19 10:35:52 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2010-12-28 09:04:28 +03:00
|
|
|
}
|
2011-03-19 05:07:16 +03:00
|
|
|
|
2012-04-18 14:43:45 +04:00
|
|
|
NS_CC_END
|