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