2010-12-28 10:23:14 +08:00
|
|
|
/****************************************************************************
|
2012-06-08 14:11:48 +08:00
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
2011-03-19 10:07:16 +08:00
|
|
|
Copyright (c) 2008-2010 Ricardo Quesada
|
2011-07-04 19:20:16 +08:00
|
|
|
Copyright (c) 2011 Zynga Inc.
|
2010-12-28 10:23:14 +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.
|
|
|
|
****************************************************************************/
|
2011-03-19 10:07:16 +08:00
|
|
|
|
|
|
|
// ideas taken from:
|
2012-04-19 14:35:52 +08:00
|
|
|
// . The ocean spray in your face [Jeff Lander]
|
|
|
|
// http://www.double.co.nz/dust/col0798.pdf
|
|
|
|
// . Building an Advanced Particle System [John van der Burg]
|
|
|
|
// http://www.gamasutra.com/features/20000623/vanderburg_01.htm
|
2011-03-19 10:07:16 +08:00
|
|
|
// . LOVE game engine
|
2012-04-19 14:35:52 +08:00
|
|
|
// http://love2d.org/
|
2011-03-19 10:07:16 +08:00
|
|
|
//
|
|
|
|
//
|
|
|
|
// Radius mode support, from 71 squared
|
2012-04-19 14:35:52 +08:00
|
|
|
// http://particledesigner.71squared.com/
|
2011-03-19 10:07:16 +08:00
|
|
|
//
|
|
|
|
// IMPORTANT: Particle Designer is supported by cocos2d, but
|
2012-09-17 15:02:24 +08:00
|
|
|
// 'Radius Mode' in Particle Designer uses a fixed emit rate of 30 hz. Since that can't be guaranteed in cocos2d,
|
2011-03-19 10:07:16 +08:00
|
|
|
// cocos2d uses a another approach, but the results are almost identical.
|
|
|
|
//
|
|
|
|
|
2010-12-28 10:23:14 +08:00
|
|
|
#include "CCParticleSystem.h"
|
2012-03-14 14:55:17 +08:00
|
|
|
#include "CCParticleBatchNode.h"
|
2010-12-28 10:23:14 +08:00
|
|
|
#include "ccTypes.h"
|
2012-06-19 16:20:46 +08:00
|
|
|
#include "textures/CCTextureCache.h"
|
|
|
|
#include "textures/CCTextureAtlas.h"
|
2010-12-28 10:23:14 +08:00
|
|
|
#include "support/base64.h"
|
2012-06-19 16:20:46 +08:00
|
|
|
#include "support/CCPointExtension.h"
|
|
|
|
#include "platform/CCFileUtils.h"
|
|
|
|
#include "platform/CCImage.h"
|
2010-12-28 10:23:14 +08:00
|
|
|
#include "platform/platform.h"
|
2010-12-31 14:56:24 +08:00
|
|
|
#include "support/zip_support/ZipUtils.h"
|
2011-11-28 17:28:43 +08:00
|
|
|
#include "CCDirector.h"
|
2012-03-14 14:55:17 +08:00
|
|
|
#include "support/CCProfiling.h"
|
2011-03-19 10:07:16 +08:00
|
|
|
// opengl
|
2012-04-25 16:18:04 +08:00
|
|
|
#include "CCGL.h"
|
2011-03-19 10:07:16 +08:00
|
|
|
|
2012-11-15 17:16:51 +08:00
|
|
|
#include <string>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2010-12-28 10:23:14 +08:00
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
NS_CC_BEGIN
|
2010-08-23 14:57:37 +08:00
|
|
|
|
2010-12-27 17:39:15 +08:00
|
|
|
// ideas taken from:
|
2012-04-19 14:35:52 +08:00
|
|
|
// . The ocean spray in your face [Jeff Lander]
|
|
|
|
// http://www.double.co.nz/dust/col0798.pdf
|
|
|
|
// . Building an Advanced Particle System [John van der Burg]
|
|
|
|
// http://www.gamasutra.com/features/20000623/vanderburg_01.htm
|
2010-12-27 17:39:15 +08:00
|
|
|
// . LOVE game engine
|
2012-04-19 14:35:52 +08:00
|
|
|
// http://love2d.org/
|
2010-12-27 17:39:15 +08:00
|
|
|
//
|
|
|
|
//
|
|
|
|
// Radius mode support, from 71 squared
|
2012-04-19 14:35:52 +08:00
|
|
|
// http://particledesigner.71squared.com/
|
2010-12-27 17:39:15 +08:00
|
|
|
//
|
|
|
|
// IMPORTANT: Particle Designer is supported by cocos2d, but
|
2012-09-17 15:02:24 +08:00
|
|
|
// 'Radius Mode' in Particle Designer uses a fixed emit rate of 30 hz. Since that can't be guaranteed in cocos2d,
|
2010-12-27 17:39:15 +08:00
|
|
|
// cocos2d uses a another approach, but the results are almost identical.
|
|
|
|
//
|
|
|
|
|
|
|
|
CCParticleSystem::CCParticleSystem()
|
2013-06-15 14:03:30 +08:00
|
|
|
: _plistFile("")
|
|
|
|
, _elapsed(0)
|
|
|
|
, _particles(NULL)
|
|
|
|
, _emitCounter(0)
|
|
|
|
, _particleIdx(0)
|
|
|
|
, _batchNode(NULL)
|
|
|
|
, _atlasIndex(0)
|
|
|
|
, _transformSystemDirty(false)
|
|
|
|
, _allocatedParticles(0)
|
|
|
|
, _isActive(true)
|
|
|
|
, _particleCount(0)
|
|
|
|
, _duration(0)
|
|
|
|
, _sourcePosition(CCPointZero)
|
|
|
|
, _posVar(CCPointZero)
|
|
|
|
, _life(0)
|
|
|
|
, _lifeVar(0)
|
|
|
|
, _angle(0)
|
|
|
|
, _angleVar(0)
|
|
|
|
, _startSize(0)
|
|
|
|
, _startSizeVar(0)
|
|
|
|
, _endSize(0)
|
|
|
|
, _endSizeVar(0)
|
|
|
|
, _startSpin(0)
|
|
|
|
, _startSpinVar(0)
|
|
|
|
, _endSpin(0)
|
|
|
|
, _endSpinVar(0)
|
|
|
|
, _emissionRate(0)
|
|
|
|
, _totalParticles(0)
|
|
|
|
, _texture(NULL)
|
|
|
|
, _opacityModifyRGB(false)
|
|
|
|
, _isBlendAdditive(false)
|
|
|
|
, _positionType(kCCPositionTypeFree)
|
|
|
|
, _isAutoRemoveOnFinish(false)
|
|
|
|
, _emitterMode(kCCParticleModeGravity)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
modeA.gravity = CCPointZero;
|
|
|
|
modeA.speed = 0;
|
|
|
|
modeA.speedVar = 0;
|
|
|
|
modeA.tangentialAccel = 0;
|
|
|
|
modeA.tangentialAccelVar = 0;
|
|
|
|
modeA.radialAccel = 0;
|
|
|
|
modeA.radialAccelVar = 0;
|
2013-01-21 17:39:48 +08:00
|
|
|
modeA.rotationIsDir = false;
|
2012-04-19 14:35:52 +08:00
|
|
|
modeB.startRadius = 0;
|
|
|
|
modeB.startRadiusVar = 0;
|
|
|
|
modeB.endRadius = 0;
|
|
|
|
modeB.endRadiusVar = 0;
|
|
|
|
modeB.rotatePerSecond = 0;
|
|
|
|
modeB.rotatePerSecondVar = 0;
|
2013-06-15 14:03:30 +08:00
|
|
|
_blendFunc.src = CC_BLEND_SRC;
|
|
|
|
_blendFunc.dst = CC_BLEND_DST;
|
2010-12-27 17:39:15 +08:00
|
|
|
}
|
|
|
|
// implementation CCParticleSystem
|
2012-06-14 15:13:16 +08:00
|
|
|
|
|
|
|
CCParticleSystem * CCParticleSystem::create(const char *plistFile)
|
2010-12-27 17:39:15 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CCParticleSystem *pRet = new CCParticleSystem();
|
|
|
|
if (pRet && pRet->initWithFile(plistFile))
|
|
|
|
{
|
|
|
|
pRet->autorelease();
|
|
|
|
return pRet;
|
|
|
|
}
|
|
|
|
CC_SAFE_DELETE(pRet);
|
|
|
|
return pRet;
|
2010-12-27 17:39:15 +08:00
|
|
|
}
|
2012-03-16 13:42:53 +08:00
|
|
|
|
2012-08-29 14:53:01 +08:00
|
|
|
CCParticleSystem* CCParticleSystem::createWithTotalParticles(unsigned int numberOfParticles)
|
|
|
|
{
|
|
|
|
CCParticleSystem *pRet = new CCParticleSystem();
|
|
|
|
if (pRet && pRet->initWithTotalParticles(numberOfParticles))
|
|
|
|
{
|
|
|
|
pRet->autorelease();
|
|
|
|
return pRet;
|
|
|
|
}
|
|
|
|
CC_SAFE_DELETE(pRet);
|
|
|
|
return pRet;
|
|
|
|
}
|
|
|
|
|
2012-03-16 13:42:53 +08:00
|
|
|
bool CCParticleSystem::init()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
return initWithTotalParticles(150);
|
2012-03-16 13:42:53 +08:00
|
|
|
}
|
|
|
|
|
2010-12-27 17:39:15 +08:00
|
|
|
bool CCParticleSystem::initWithFile(const char *plistFile)
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
bool bRet = false;
|
2013-06-15 14:03:30 +08:00
|
|
|
_plistFile = CCFileUtils::sharedFileUtils()->fullPathForFilename(plistFile);
|
|
|
|
CCDictionary *dict = CCDictionary::createWithContentsOfFileThreadSafe(_plistFile.c_str());
|
2010-12-27 17:39:15 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
CCAssert( dict != NULL, "Particles: file not found");
|
2012-11-15 17:16:51 +08:00
|
|
|
|
|
|
|
// XXX compute path from a path, should define a function somewhere to do it
|
|
|
|
string listFilePath = plistFile;
|
|
|
|
if (listFilePath.find('/') != string::npos)
|
|
|
|
{
|
|
|
|
listFilePath = listFilePath.substr(0, listFilePath.rfind('/') + 1);
|
|
|
|
bRet = this->initWithDictionary(dict, listFilePath.c_str());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bRet = this->initWithDictionary(dict, "");
|
|
|
|
}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
dict->release();
|
2011-11-15 10:41:18 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
return bRet;
|
2010-12-27 17:39:15 +08:00
|
|
|
}
|
|
|
|
|
2012-03-20 15:04:53 +08:00
|
|
|
bool CCParticleSystem::initWithDictionary(CCDictionary *dictionary)
|
2012-11-15 17:16:51 +08:00
|
|
|
{
|
|
|
|
return initWithDictionary(dictionary, "");
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CCParticleSystem::initWithDictionary(CCDictionary *dictionary, const char *dirname)
|
2010-12-27 17:39:15 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
bool bRet = false;
|
|
|
|
unsigned char *buffer = NULL;
|
|
|
|
unsigned char *deflated = NULL;
|
|
|
|
CCImage *image = NULL;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
int maxParticles = dictionary->valueForKey("maxParticles")->intValue();
|
|
|
|
// self, not super
|
|
|
|
if(this->initWithTotalParticles(maxParticles))
|
|
|
|
{
|
|
|
|
// angle
|
2013-06-15 14:03:30 +08:00
|
|
|
_angle = dictionary->valueForKey("angle")->floatValue();
|
|
|
|
_angleVar = dictionary->valueForKey("angleVariance")->floatValue();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// duration
|
2013-06-15 14:03:30 +08:00
|
|
|
_duration = dictionary->valueForKey("duration")->floatValue();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// blend function
|
2013-06-15 14:03:30 +08:00
|
|
|
_blendFunc.src = dictionary->valueForKey("blendFuncSource")->intValue();
|
|
|
|
_blendFunc.dst = dictionary->valueForKey("blendFuncDestination")->intValue();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// color
|
2013-06-15 14:03:30 +08:00
|
|
|
_startColor.r = dictionary->valueForKey("startColorRed")->floatValue();
|
|
|
|
_startColor.g = dictionary->valueForKey("startColorGreen")->floatValue();
|
|
|
|
_startColor.b = dictionary->valueForKey("startColorBlue")->floatValue();
|
|
|
|
_startColor.a = dictionary->valueForKey("startColorAlpha")->floatValue();
|
|
|
|
|
|
|
|
_startColorVar.r = dictionary->valueForKey("startColorVarianceRed")->floatValue();
|
|
|
|
_startColorVar.g = dictionary->valueForKey("startColorVarianceGreen")->floatValue();
|
|
|
|
_startColorVar.b = dictionary->valueForKey("startColorVarianceBlue")->floatValue();
|
|
|
|
_startColorVar.a = dictionary->valueForKey("startColorVarianceAlpha")->floatValue();
|
|
|
|
|
|
|
|
_endColor.r = dictionary->valueForKey("finishColorRed")->floatValue();
|
|
|
|
_endColor.g = dictionary->valueForKey("finishColorGreen")->floatValue();
|
|
|
|
_endColor.b = dictionary->valueForKey("finishColorBlue")->floatValue();
|
|
|
|
_endColor.a = dictionary->valueForKey("finishColorAlpha")->floatValue();
|
|
|
|
|
|
|
|
_endColorVar.r = dictionary->valueForKey("finishColorVarianceRed")->floatValue();
|
|
|
|
_endColorVar.g = dictionary->valueForKey("finishColorVarianceGreen")->floatValue();
|
|
|
|
_endColorVar.b = dictionary->valueForKey("finishColorVarianceBlue")->floatValue();
|
|
|
|
_endColorVar.a = dictionary->valueForKey("finishColorVarianceAlpha")->floatValue();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// particle size
|
2013-06-15 14:03:30 +08:00
|
|
|
_startSize = dictionary->valueForKey("startParticleSize")->floatValue();
|
|
|
|
_startSizeVar = dictionary->valueForKey("startParticleSizeVariance")->floatValue();
|
|
|
|
_endSize = dictionary->valueForKey("finishParticleSize")->floatValue();
|
|
|
|
_endSizeVar = dictionary->valueForKey("finishParticleSizeVariance")->floatValue();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// position
|
2012-04-14 19:11:57 +08:00
|
|
|
float x = dictionary->valueForKey("sourcePositionx")->floatValue();
|
|
|
|
float y = dictionary->valueForKey("sourcePositiony")->floatValue();
|
2012-04-19 14:35:52 +08:00
|
|
|
this->setPosition( ccp(x,y) );
|
2013-06-15 14:03:30 +08:00
|
|
|
_posVar.x = dictionary->valueForKey("sourcePositionVariancex")->floatValue();
|
|
|
|
_posVar.y = dictionary->valueForKey("sourcePositionVariancey")->floatValue();
|
2010-12-27 17:39:15 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// Spinning
|
2013-06-15 14:03:30 +08:00
|
|
|
_startSpin = dictionary->valueForKey("rotationStart")->floatValue();
|
|
|
|
_startSpinVar = dictionary->valueForKey("rotationStartVariance")->floatValue();
|
|
|
|
_endSpin= dictionary->valueForKey("rotationEnd")->floatValue();
|
|
|
|
_endSpinVar= dictionary->valueForKey("rotationEndVariance")->floatValue();
|
2011-07-04 19:20:16 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitterMode = dictionary->valueForKey("emitterType")->intValue();
|
2010-12-27 17:39:15 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// Mode A: Gravity + tangential accel + radial accel
|
2013-06-15 14:03:30 +08:00
|
|
|
if( _emitterMode == kCCParticleModeGravity )
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
// gravity
|
|
|
|
modeA.gravity.x = dictionary->valueForKey("gravityx")->floatValue();
|
|
|
|
modeA.gravity.y = dictionary->valueForKey("gravityy")->floatValue();
|
2010-08-23 14:57:37 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// speed
|
|
|
|
modeA.speed = dictionary->valueForKey("speed")->floatValue();
|
|
|
|
modeA.speedVar = dictionary->valueForKey("speedVariance")->floatValue();
|
2010-08-23 14:57:37 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// radial acceleration
|
2012-04-14 19:11:57 +08:00
|
|
|
modeA.radialAccel = dictionary->valueForKey("radialAcceleration")->floatValue();
|
2012-04-19 14:35:52 +08:00
|
|
|
modeA.radialAccelVar = dictionary->valueForKey("radialAccelVariance")->floatValue();
|
|
|
|
|
|
|
|
// tangential acceleration
|
|
|
|
modeA.tangentialAccel = dictionary->valueForKey("tangentialAcceleration")->floatValue();
|
|
|
|
modeA.tangentialAccelVar = dictionary->valueForKey("tangentialAccelVariance")->floatValue();
|
2013-01-21 17:39:48 +08:00
|
|
|
|
|
|
|
// rotation is dir
|
|
|
|
modeA.rotationIsDir = dictionary->valueForKey("rotationIsDir")->boolValue();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// or Mode B: radius movement
|
2013-06-15 14:03:30 +08:00
|
|
|
else if( _emitterMode == kCCParticleModeRadius )
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
modeB.startRadius = dictionary->valueForKey("maxRadius")->floatValue();
|
|
|
|
modeB.startRadiusVar = dictionary->valueForKey("maxRadiusVariance")->floatValue();
|
|
|
|
modeB.endRadius = dictionary->valueForKey("minRadius")->floatValue();
|
|
|
|
modeB.endRadiusVar = 0.0f;
|
|
|
|
modeB.rotatePerSecond = dictionary->valueForKey("rotatePerSecond")->floatValue();
|
|
|
|
modeB.rotatePerSecondVar = dictionary->valueForKey("rotatePerSecondVariance")->floatValue();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
CCAssert( false, "Invalid emitterType in config file");
|
|
|
|
CC_BREAK_IF(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// life span
|
2013-06-15 14:03:30 +08:00
|
|
|
_life = dictionary->valueForKey("particleLifespan")->floatValue();
|
|
|
|
_lifeVar = dictionary->valueForKey("particleLifespanVariance")->floatValue();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// emission Rate
|
2013-06-15 14:03:30 +08:00
|
|
|
_emissionRate = _totalParticles / _life;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
//don't get the internal texture if a batchNode is used
|
2013-06-15 14:03:30 +08:00
|
|
|
if (!_batchNode)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2012-06-12 01:43:07 +08:00
|
|
|
// Set a compatible default for the alpha transfer
|
2013-06-15 14:03:30 +08:00
|
|
|
_opacityModifyRGB = false;
|
2012-06-08 14:11:48 +08:00
|
|
|
|
2012-04-24 15:02:18 +08:00
|
|
|
// texture
|
|
|
|
// Try to get the texture from the cache
|
2012-11-21 17:22:26 +08:00
|
|
|
std::string textureName = dictionary->valueForKey("textureFileName")->getCString();
|
2012-11-15 17:16:51 +08:00
|
|
|
|
2012-11-21 17:22:26 +08:00
|
|
|
size_t rPos = textureName.rfind('/');
|
|
|
|
|
|
|
|
if (rPos != string::npos)
|
2012-11-15 17:16:51 +08:00
|
|
|
{
|
2012-11-21 17:22:26 +08:00
|
|
|
string textureDir = textureName.substr(0, rPos + 1);
|
|
|
|
|
|
|
|
if (dirname != NULL && textureDir != dirname)
|
|
|
|
{
|
|
|
|
textureName = textureName.substr(rPos+1);
|
|
|
|
textureName = string(dirname) + textureName;
|
|
|
|
}
|
2012-11-15 17:16:51 +08:00
|
|
|
}
|
2013-01-17 11:42:41 +08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (dirname != NULL)
|
|
|
|
{
|
|
|
|
textureName = string(dirname) + textureName;
|
|
|
|
}
|
|
|
|
}
|
2012-04-24 15:02:18 +08:00
|
|
|
|
|
|
|
CCTexture2D *tex = NULL;
|
|
|
|
|
2012-11-21 17:22:26 +08:00
|
|
|
if (textureName.length() > 0)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2012-04-24 15:02:18 +08:00
|
|
|
// set not pop-up message box when load image failed
|
2012-06-15 16:47:30 +08:00
|
|
|
bool bNotify = CCFileUtils::sharedFileUtils()->isPopupNotify();
|
2012-06-20 14:38:13 +08:00
|
|
|
CCFileUtils::sharedFileUtils()->setPopupNotify(false);
|
2013-01-25 20:59:58 +08:00
|
|
|
tex = CCTextureCache::sharedTextureCache()->addImage(textureName.c_str());
|
2012-04-24 15:02:18 +08:00
|
|
|
// reset the value of UIImage notify
|
2012-06-20 14:38:13 +08:00
|
|
|
CCFileUtils::sharedFileUtils()->setPopupNotify(bNotify);
|
2012-04-24 15:02:18 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (tex)
|
|
|
|
{
|
|
|
|
setTexture(tex);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const char *textureData = dictionary->valueForKey("textureImageData")->getCString();
|
|
|
|
CCAssert(textureData, "");
|
|
|
|
|
|
|
|
int dataLen = strlen(textureData);
|
|
|
|
if(dataLen != 0)
|
|
|
|
{
|
|
|
|
// if it fails, try to get it from the base64-gzipped data
|
|
|
|
int decodeLen = base64Decode((unsigned char*)textureData, (unsigned int)dataLen, &buffer);
|
|
|
|
CCAssert( buffer != NULL, "CCParticleSystem: error decoding textureImageData");
|
|
|
|
CC_BREAK_IF(!buffer);
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
int deflatedLen = ZipUtils::ccInflateMemory(buffer, decodeLen, &deflated);
|
|
|
|
CCAssert( deflated != NULL, "CCParticleSystem: error ungzipping textureImageData");
|
|
|
|
CC_BREAK_IF(!deflated);
|
|
|
|
|
2012-05-23 11:26:21 +08:00
|
|
|
// For android, we should retain it in VolatileTexture::addCCImage which invoked in CCTextureCache::sharedTextureCache()->addUIImage()
|
2012-04-19 14:35:52 +08:00
|
|
|
image = new CCImage();
|
|
|
|
bool isOK = image->initWithImageData(deflated, deflatedLen);
|
|
|
|
CCAssert(isOK, "CCParticleSystem: error init image with Data");
|
|
|
|
CC_BREAK_IF(!isOK);
|
|
|
|
|
2012-11-21 17:22:26 +08:00
|
|
|
setTexture(CCTextureCache::sharedTextureCache()->addUIImage(image, textureName.c_str()));
|
2012-05-23 11:18:04 +08:00
|
|
|
|
|
|
|
image->release();
|
2012-04-24 15:02:18 +08:00
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2013-06-15 14:03:30 +08:00
|
|
|
CCAssert( this->_texture != NULL, "CCParticleSystem: error loading the texture");
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
bRet = true;
|
|
|
|
}
|
|
|
|
} while (0);
|
|
|
|
CC_SAFE_DELETE_ARRAY(buffer);
|
2011-03-19 10:07:16 +08:00
|
|
|
CC_SAFE_DELETE_ARRAY(deflated);
|
2012-04-19 14:35:52 +08:00
|
|
|
return bRet;
|
2010-12-27 17:39:15 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2011-07-04 19:20:16 +08:00
|
|
|
bool CCParticleSystem::initWithTotalParticles(unsigned int numberOfParticles)
|
2010-12-27 17:39:15 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_totalParticles = numberOfParticles;
|
2010-08-23 14:57:37 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
CC_SAFE_FREE(_particles);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_particles = (tCCParticle*)calloc(_totalParticles, sizeof(tCCParticle));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if( ! _particles )
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
CCLOG("Particle system: not enough memory");
|
|
|
|
this->release();
|
|
|
|
return false;
|
|
|
|
}
|
2013-06-15 14:03:30 +08:00
|
|
|
_allocatedParticles = numberOfParticles;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_batchNode)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
for (unsigned int i = 0; i < _totalParticles; i++)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_particles[i].atlasIndex=i;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
// default, active
|
2013-06-15 14:03:30 +08:00
|
|
|
_isActive = true;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// default blend function
|
2013-06-15 14:03:30 +08:00
|
|
|
_blendFunc.src = CC_BLEND_SRC;
|
|
|
|
_blendFunc.dst = CC_BLEND_DST;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// default movement type;
|
2013-06-15 14:03:30 +08:00
|
|
|
_positionType = kCCPositionTypeFree;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// by default be in mode A:
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitterMode = kCCParticleModeGravity;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// default: modulate
|
|
|
|
// XXX: not used
|
|
|
|
// colorModulate = YES;
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_isAutoRemoveOnFinish = false;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2012-09-17 15:02:24 +08:00
|
|
|
// Optimization: compile updateParticle method
|
2012-04-19 14:35:52 +08:00
|
|
|
//updateParticleSel = @selector(updateQuadWithParticle:newPosition:);
|
|
|
|
//updateParticleImp = (CC_UPDATE_PARTICLE_IMP) [self methodForSelector:updateParticleSel];
|
|
|
|
//for batchNode
|
2013-06-15 14:03:30 +08:00
|
|
|
_transformSystemDirty = false;
|
2012-09-17 15:02:24 +08:00
|
|
|
// update after action in run!
|
2012-04-19 14:35:52 +08:00
|
|
|
this->scheduleUpdateWithPriority(1);
|
|
|
|
|
|
|
|
return true;
|
2010-12-27 17:39:15 +08:00
|
|
|
}
|
2010-08-23 14:57:37 +08:00
|
|
|
|
2010-12-27 17:39:15 +08:00
|
|
|
CCParticleSystem::~CCParticleSystem()
|
|
|
|
{
|
2013-02-27 16:26:42 +08:00
|
|
|
// Since the scheduler retains the "target (in this case the ParticleSystem)
|
|
|
|
// it is not needed to call "unscheduleUpdate" here. In fact, it will be called in "cleanup"
|
|
|
|
//unscheduleUpdate();
|
2013-06-15 14:03:30 +08:00
|
|
|
CC_SAFE_FREE(_particles);
|
|
|
|
CC_SAFE_RELEASE(_texture);
|
2010-12-27 17:39:15 +08:00
|
|
|
}
|
2012-03-14 14:55:17 +08:00
|
|
|
|
2010-12-27 17:39:15 +08:00
|
|
|
bool CCParticleSystem::addParticle()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
if (this->isFull())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2010-08-23 14:57:37 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
tCCParticle * particle = &_particles[ _particleCount ];
|
2012-04-19 14:35:52 +08:00
|
|
|
this->initParticle(particle);
|
2013-06-15 14:03:30 +08:00
|
|
|
++_particleCount;
|
2010-08-23 14:57:37 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
return true;
|
2010-12-27 17:39:15 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2010-12-27 17:39:15 +08:00
|
|
|
void CCParticleSystem::initParticle(tCCParticle* particle)
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
// timeToLive
|
|
|
|
// no negative life. prevent division by 0
|
2013-06-15 14:03:30 +08:00
|
|
|
particle->timeToLive = _life + _lifeVar * CCRANDOM_MINUS1_1();
|
2012-04-19 14:35:52 +08:00
|
|
|
particle->timeToLive = MAX(0, particle->timeToLive);
|
|
|
|
|
|
|
|
// position
|
2013-06-15 14:03:30 +08:00
|
|
|
particle->pos.x = _sourcePosition.x + _posVar.x * CCRANDOM_MINUS1_1();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
particle->pos.y = _sourcePosition.y + _posVar.y * CCRANDOM_MINUS1_1();
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
|
|
|
|
// Color
|
|
|
|
ccColor4F start;
|
2013-06-15 14:03:30 +08:00
|
|
|
start.r = clampf(_startColor.r + _startColorVar.r * CCRANDOM_MINUS1_1(), 0, 1);
|
|
|
|
start.g = clampf(_startColor.g + _startColorVar.g * CCRANDOM_MINUS1_1(), 0, 1);
|
|
|
|
start.b = clampf(_startColor.b + _startColorVar.b * CCRANDOM_MINUS1_1(), 0, 1);
|
|
|
|
start.a = clampf(_startColor.a + _startColorVar.a * CCRANDOM_MINUS1_1(), 0, 1);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
ccColor4F end;
|
2013-06-15 14:03:30 +08:00
|
|
|
end.r = clampf(_endColor.r + _endColorVar.r * CCRANDOM_MINUS1_1(), 0, 1);
|
|
|
|
end.g = clampf(_endColor.g + _endColorVar.g * CCRANDOM_MINUS1_1(), 0, 1);
|
|
|
|
end.b = clampf(_endColor.b + _endColorVar.b * CCRANDOM_MINUS1_1(), 0, 1);
|
|
|
|
end.a = clampf(_endColor.a + _endColorVar.a * CCRANDOM_MINUS1_1(), 0, 1);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
particle->color = start;
|
|
|
|
particle->deltaColor.r = (end.r - start.r) / particle->timeToLive;
|
|
|
|
particle->deltaColor.g = (end.g - start.g) / particle->timeToLive;
|
|
|
|
particle->deltaColor.b = (end.b - start.b) / particle->timeToLive;
|
|
|
|
particle->deltaColor.a = (end.a - start.a) / particle->timeToLive;
|
|
|
|
|
|
|
|
// size
|
2013-06-15 14:03:30 +08:00
|
|
|
float startS = _startSize + _startSizeVar * CCRANDOM_MINUS1_1();
|
2012-04-19 14:35:52 +08:00
|
|
|
startS = MAX(0, startS); // No negative value
|
|
|
|
|
|
|
|
particle->size = startS;
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if( _endSize == kCCParticleStartSizeEqualToEndSize )
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
particle->deltaSize = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
float endS = _endSize + _endSizeVar * CCRANDOM_MINUS1_1();
|
2012-04-19 14:35:52 +08:00
|
|
|
endS = MAX(0, endS); // No negative values
|
|
|
|
particle->deltaSize = (endS - startS) / particle->timeToLive;
|
|
|
|
}
|
|
|
|
|
|
|
|
// rotation
|
2013-06-15 14:03:30 +08:00
|
|
|
float startA = _startSpin + _startSpinVar * CCRANDOM_MINUS1_1();
|
|
|
|
float endA = _endSpin + _endSpinVar * CCRANDOM_MINUS1_1();
|
2012-04-19 14:35:52 +08:00
|
|
|
particle->rotation = startA;
|
|
|
|
particle->deltaRotation = (endA - startA) / particle->timeToLive;
|
|
|
|
|
|
|
|
// position
|
2013-06-15 14:03:30 +08:00
|
|
|
if( _positionType == kCCPositionTypeFree )
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
particle->startPos = this->convertToWorldSpace(CCPointZero);
|
|
|
|
}
|
2013-06-15 14:03:30 +08:00
|
|
|
else if ( _positionType == kCCPositionTypeRelative )
|
2010-12-27 17:39:15 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
particle->startPos = _position;
|
2010-12-27 17:39:15 +08:00
|
|
|
}
|
2010-08-23 14:57:37 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// direction
|
2013-06-15 14:03:30 +08:00
|
|
|
float a = CC_DEGREES_TO_RADIANS( _angle + _angleVar * CCRANDOM_MINUS1_1() );
|
2010-08-23 14:57:37 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// Mode Gravity: A
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_emitterMode == kCCParticleModeGravity)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
CCPoint v(cosf( a ), sinf( a ));
|
|
|
|
float s = modeA.speed + modeA.speedVar * CCRANDOM_MINUS1_1();
|
2010-08-23 14:57:37 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// direction
|
|
|
|
particle->modeA.dir = ccpMult( v, s );
|
2010-08-23 14:57:37 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// radial accel
|
|
|
|
particle->modeA.radialAccel = modeA.radialAccel + modeA.radialAccelVar * CCRANDOM_MINUS1_1();
|
2012-03-14 14:55:17 +08:00
|
|
|
|
2010-08-23 14:57:37 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// tangential accel
|
|
|
|
particle->modeA.tangentialAccel = modeA.tangentialAccel + modeA.tangentialAccelVar * CCRANDOM_MINUS1_1();
|
2012-03-14 14:55:17 +08:00
|
|
|
|
2013-01-21 17:39:48 +08:00
|
|
|
// rotation is dir
|
|
|
|
if(modeA.rotationIsDir)
|
|
|
|
particle->rotation = -CC_RADIANS_TO_DEGREES(ccpToAngle(particle->modeA.dir));
|
2010-12-27 17:39:15 +08:00
|
|
|
}
|
2010-08-23 14:57:37 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// Mode Radius: B
|
2012-04-24 15:02:18 +08:00
|
|
|
else
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
// Set the default diameter of the particle from the source position
|
|
|
|
float startRadius = modeB.startRadius + modeB.startRadiusVar * CCRANDOM_MINUS1_1();
|
|
|
|
float endRadius = modeB.endRadius + modeB.endRadiusVar * CCRANDOM_MINUS1_1();
|
2010-08-23 14:57:37 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
particle->modeB.radius = startRadius;
|
2010-08-23 14:57:37 +08:00
|
|
|
|
2012-04-24 15:02:18 +08:00
|
|
|
if(modeB.endRadius == kCCParticleStartRadiusEqualToEndRadius)
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
particle->modeB.deltaRadius = 0;
|
2012-04-24 15:02:18 +08:00
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
else
|
2012-04-24 15:02:18 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
particle->modeB.deltaRadius = (endRadius - startRadius) / particle->timeToLive;
|
2012-04-24 15:02:18 +08:00
|
|
|
}
|
2010-08-23 14:57:37 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
particle->modeB.angle = a;
|
|
|
|
particle->modeB.degreesPerSecond = CC_DEGREES_TO_RADIANS(modeB.rotatePerSecond + modeB.rotatePerSecondVar * CCRANDOM_MINUS1_1());
|
|
|
|
}
|
2010-12-27 17:39:15 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2010-12-27 17:39:15 +08:00
|
|
|
void CCParticleSystem::stopSystem()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_isActive = false;
|
|
|
|
_elapsed = _duration;
|
|
|
|
_emitCounter = 0;
|
2010-12-27 17:39:15 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2010-12-27 17:39:15 +08:00
|
|
|
void CCParticleSystem::resetSystem()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_isActive = true;
|
|
|
|
_elapsed = 0;
|
|
|
|
for (_particleIdx = 0; _particleIdx < _particleCount; ++_particleIdx)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
tCCParticle *p = &_particles[_particleIdx];
|
2012-04-19 14:35:52 +08:00
|
|
|
p->timeToLive = 0;
|
|
|
|
}
|
2010-12-27 17:39:15 +08:00
|
|
|
}
|
|
|
|
bool CCParticleSystem::isFull()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return (_particleCount == _totalParticles);
|
2010-12-27 17:39:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ParticleSystem - MainLoop
|
2012-06-08 13:55:28 +08:00
|
|
|
void CCParticleSystem::update(float dt)
|
2010-12-27 17:39:15 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CC_PROFILER_START_CATEGORY(kCCProfilerCategoryParticles , "CCParticleSystem - update");
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_isActive && _emissionRate)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
float rate = 1.0f / _emissionRate;
|
2012-04-19 14:35:52 +08:00
|
|
|
//issue #1201, prevent bursts of particles, due to too high emitCounter
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_particleCount < _totalParticles)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitCounter += dt;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
while (_particleCount < _totalParticles && _emitCounter > rate)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
this->addParticle();
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitCounter -= rate;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_elapsed += dt;
|
|
|
|
if (_duration != -1 && _duration < _elapsed)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
this->stopSystem();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_particleIdx = 0;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
CCPoint currentPosition = CCPointZero;
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_positionType == kCCPositionTypeFree)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
currentPosition = this->convertToWorldSpace(CCPointZero);
|
|
|
|
}
|
2013-06-15 14:03:30 +08:00
|
|
|
else if (_positionType == kCCPositionTypeRelative)
|
2010-12-27 17:39:15 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
currentPosition = _position;
|
2010-12-27 17:39:15 +08:00
|
|
|
}
|
2010-08-23 14:57:37 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_visible)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
while (_particleIdx < _particleCount)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
tCCParticle *p = &_particles[_particleIdx];
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// life
|
|
|
|
p->timeToLive -= dt;
|
|
|
|
|
2012-04-24 15:02:18 +08:00
|
|
|
if (p->timeToLive > 0)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
// Mode A: gravity, direction, tangential accel & radial accel
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_emitterMode == kCCParticleModeGravity)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
CCPoint tmp, radial, tangential;
|
|
|
|
|
|
|
|
radial = CCPointZero;
|
|
|
|
// radial acceleration
|
2012-04-24 15:02:18 +08:00
|
|
|
if (p->pos.x || p->pos.y)
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
radial = ccpNormalize(p->pos);
|
2012-04-24 15:02:18 +08:00
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
tangential = radial;
|
|
|
|
radial = ccpMult(radial, p->modeA.radialAccel);
|
|
|
|
|
|
|
|
// tangential acceleration
|
|
|
|
float newy = tangential.x;
|
|
|
|
tangential.x = -tangential.y;
|
|
|
|
tangential.y = newy;
|
|
|
|
tangential = ccpMult(tangential, p->modeA.tangentialAccel);
|
|
|
|
|
|
|
|
// (gravity + radial + tangential) * dt
|
|
|
|
tmp = ccpAdd( ccpAdd( radial, tangential), modeA.gravity);
|
|
|
|
tmp = ccpMult( tmp, dt);
|
|
|
|
p->modeA.dir = ccpAdd( p->modeA.dir, tmp);
|
|
|
|
tmp = ccpMult(p->modeA.dir, dt);
|
|
|
|
p->pos = ccpAdd( p->pos, tmp );
|
|
|
|
}
|
|
|
|
|
|
|
|
// Mode B: radius movement
|
2012-04-24 15:02:18 +08:00
|
|
|
else
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
// Update the angle and radius of the particle.
|
|
|
|
p->modeB.angle += p->modeB.degreesPerSecond * dt;
|
|
|
|
p->modeB.radius += p->modeB.deltaRadius * dt;
|
|
|
|
|
|
|
|
p->pos.x = - cosf(p->modeB.angle) * p->modeB.radius;
|
|
|
|
p->pos.y = - sinf(p->modeB.angle) * p->modeB.radius;
|
|
|
|
}
|
|
|
|
|
|
|
|
// color
|
|
|
|
p->color.r += (p->deltaColor.r * dt);
|
|
|
|
p->color.g += (p->deltaColor.g * dt);
|
|
|
|
p->color.b += (p->deltaColor.b * dt);
|
|
|
|
p->color.a += (p->deltaColor.a * dt);
|
|
|
|
|
|
|
|
// size
|
|
|
|
p->size += (p->deltaSize * dt);
|
|
|
|
p->size = MAX( 0, p->size );
|
|
|
|
|
|
|
|
// angle
|
|
|
|
p->rotation += (p->deltaRotation * dt);
|
|
|
|
|
|
|
|
//
|
|
|
|
// update values in quad
|
|
|
|
//
|
|
|
|
|
|
|
|
CCPoint newPos;
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_positionType == kCCPositionTypeFree || _positionType == kCCPositionTypeRelative)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
CCPoint diff = ccpSub( currentPosition, p->startPos );
|
|
|
|
newPos = ccpSub(p->pos, diff);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
newPos = p->pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
// translate newPos to correct position, since matrix transform isn't performed in batchnode
|
|
|
|
// don't update the particle with the new position information, it will interfere with the radius and tangential calculations
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_batchNode)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
newPos.x+=_position.x;
|
|
|
|
newPos.y+=_position.y;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
updateQuadWithParticle(p, newPos);
|
|
|
|
//updateParticleImp(self, updateParticleSel, p, newPos);
|
|
|
|
|
|
|
|
// update particle counter
|
2013-06-15 14:03:30 +08:00
|
|
|
++_particleIdx;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// life < 0
|
|
|
|
int currentIndex = p->atlasIndex;
|
2013-06-15 14:03:30 +08:00
|
|
|
if( _particleIdx != _particleCount-1 )
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_particles[_particleIdx] = _particles[_particleCount-1];
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_batchNode)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
//disable the switched particle
|
2013-06-15 14:03:30 +08:00
|
|
|
_batchNode->disableParticle(_atlasIndex+currentIndex);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
//switch indexes
|
2013-06-15 14:03:30 +08:00
|
|
|
_particles[_particleCount-1].atlasIndex = currentIndex;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
--_particleCount;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if( _particleCount == 0 && _isAutoRemoveOnFinish )
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
this->unscheduleUpdate();
|
2013-06-15 14:03:30 +08:00
|
|
|
_parent->removeChild(this, true);
|
2012-04-19 14:35:52 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} //while
|
2013-06-15 14:03:30 +08:00
|
|
|
_transformSystemDirty = false;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2013-06-15 14:03:30 +08:00
|
|
|
if (! _batchNode)
|
2012-04-24 15:02:18 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
postStep();
|
2012-04-24 15:02:18 +08:00
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
CC_PROFILER_STOP_CATEGORY(kCCProfilerCategoryParticles , "CCParticleSystem - update");
|
2012-03-14 14:55:17 +08:00
|
|
|
}
|
2010-08-23 14:57:37 +08:00
|
|
|
|
2012-03-14 14:55:17 +08:00
|
|
|
void CCParticleSystem::updateWithNoTime(void)
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
this->update(0.0f);
|
2010-12-27 17:39:15 +08:00
|
|
|
}
|
2012-03-14 14:55:17 +08:00
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
void CCParticleSystem::updateQuadWithParticle(tCCParticle* particle, const CCPoint& newPosition)
|
2010-12-27 17:39:15 +08:00
|
|
|
{
|
2011-06-10 17:51:37 +08:00
|
|
|
CC_UNUSED_PARAM(particle);
|
|
|
|
CC_UNUSED_PARAM(newPosition);
|
2012-09-17 15:02:24 +08:00
|
|
|
// should be overridden
|
2010-12-27 17:39:15 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2010-12-27 17:39:15 +08:00
|
|
|
void CCParticleSystem::postStep()
|
|
|
|
{
|
2012-09-17 15:02:24 +08:00
|
|
|
// should be overridden
|
2010-12-27 17:39:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ParticleSystem - CCTexture protocol
|
|
|
|
void CCParticleSystem::setTexture(CCTexture2D* var)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_texture != var)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2012-06-08 14:11:48 +08:00
|
|
|
CC_SAFE_RETAIN(var);
|
2013-06-15 14:03:30 +08:00
|
|
|
CC_SAFE_RELEASE(_texture);
|
|
|
|
_texture = var;
|
2012-06-08 14:11:48 +08:00
|
|
|
updateBlendFunc();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCParticleSystem::updateBlendFunc()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
CCAssert(! _batchNode, "Can't change blending functions when the particle is being batched");
|
2010-12-27 17:39:15 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if(_texture)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
bool premultiplied = _texture->hasPremultipliedAlpha();
|
2012-06-12 01:43:07 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_opacityModifyRGB = false;
|
2012-06-12 01:43:07 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if( _texture && ( _blendFunc.src == CC_BLEND_SRC && _blendFunc.dst == CC_BLEND_DST ) )
|
2012-06-12 01:43:07 +08:00
|
|
|
{
|
|
|
|
if( premultiplied )
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_opacityModifyRGB = true;
|
2012-06-12 01:43:07 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_blendFunc.src = GL_SRC_ALPHA;
|
|
|
|
_blendFunc.dst = GL_ONE_MINUS_SRC_ALPHA;
|
2012-06-12 01:43:07 +08:00
|
|
|
}
|
|
|
|
}
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
2010-12-27 17:39:15 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2010-12-27 17:39:15 +08:00
|
|
|
CCTexture2D * CCParticleSystem::getTexture()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _texture;
|
2010-12-27 17:39:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ParticleSystem - Additive Blending
|
2012-06-15 15:10:40 +08:00
|
|
|
void CCParticleSystem::setBlendAdditive(bool additive)
|
2010-12-27 17:39:15 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
if( additive )
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_blendFunc.src = GL_SRC_ALPHA;
|
|
|
|
_blendFunc.dst = GL_ONE;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if( _texture && ! _texture->hasPremultipliedAlpha() )
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_blendFunc.src = GL_SRC_ALPHA;
|
|
|
|
_blendFunc.dst = GL_ONE_MINUS_SRC_ALPHA;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_blendFunc.src = CC_BLEND_SRC;
|
|
|
|
_blendFunc.dst = CC_BLEND_DST;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
}
|
2010-12-27 17:39:15 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2012-06-15 15:10:40 +08:00
|
|
|
bool CCParticleSystem::isBlendAdditive()
|
2010-12-27 17:39:15 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return( _blendFunc.src == GL_SRC_ALPHA && _blendFunc.dst == GL_ONE);
|
2010-12-27 17:39:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ParticleSystem - Properties of Gravity Mode
|
|
|
|
void CCParticleSystem::setTangentialAccel(float t)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
CCAssert( _emitterMode == kCCParticleModeGravity, "Particle Mode should be Gravity");
|
2012-04-19 14:35:52 +08:00
|
|
|
modeA.tangentialAccel = t;
|
2010-12-27 17:39:15 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2010-12-27 17:39:15 +08:00
|
|
|
float CCParticleSystem::getTangentialAccel()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
CCAssert( _emitterMode == kCCParticleModeGravity, "Particle Mode should be Gravity");
|
2012-04-19 14:35:52 +08:00
|
|
|
return modeA.tangentialAccel;
|
2010-12-27 17:39:15 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2010-12-27 17:39:15 +08:00
|
|
|
void CCParticleSystem::setTangentialAccelVar(float t)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
CCAssert( _emitterMode == kCCParticleModeGravity, "Particle Mode should be Gravity");
|
2012-04-19 14:35:52 +08:00
|
|
|
modeA.tangentialAccelVar = t;
|
2010-12-27 17:39:15 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2010-12-27 17:39:15 +08:00
|
|
|
float CCParticleSystem::getTangentialAccelVar()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
CCAssert( _emitterMode == kCCParticleModeGravity, "Particle Mode should be Gravity");
|
2012-04-19 14:35:52 +08:00
|
|
|
return modeA.tangentialAccelVar;
|
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2010-12-27 17:39:15 +08:00
|
|
|
void CCParticleSystem::setRadialAccel(float t)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
CCAssert( _emitterMode == kCCParticleModeGravity, "Particle Mode should be Gravity");
|
2012-04-19 14:35:52 +08:00
|
|
|
modeA.radialAccel = t;
|
2010-12-27 17:39:15 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2010-12-27 17:39:15 +08:00
|
|
|
float CCParticleSystem::getRadialAccel()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
CCAssert( _emitterMode == kCCParticleModeGravity, "Particle Mode should be Gravity");
|
2012-04-19 14:35:52 +08:00
|
|
|
return modeA.radialAccel;
|
2010-12-27 17:39:15 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2010-12-27 17:39:15 +08:00
|
|
|
void CCParticleSystem::setRadialAccelVar(float t)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
CCAssert( _emitterMode == kCCParticleModeGravity, "Particle Mode should be Gravity");
|
2012-04-19 14:35:52 +08:00
|
|
|
modeA.radialAccelVar = t;
|
2010-12-27 17:39:15 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2010-12-27 17:39:15 +08:00
|
|
|
float CCParticleSystem::getRadialAccelVar()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
CCAssert( _emitterMode == kCCParticleModeGravity, "Particle Mode should be Gravity");
|
2012-04-19 14:35:52 +08:00
|
|
|
return modeA.radialAccelVar;
|
2010-12-27 17:39:15 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2013-01-21 17:39:48 +08:00
|
|
|
void CCParticleSystem::setRotationIsDir(bool t)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
CCAssert( _emitterMode == kCCParticleModeGravity, "Particle Mode should be Gravity");
|
2013-01-21 17:39:48 +08:00
|
|
|
modeA.rotationIsDir = t;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool CCParticleSystem::getRotationIsDir()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
CCAssert( _emitterMode == kCCParticleModeGravity, "Particle Mode should be Gravity");
|
2013-01-21 17:39:48 +08:00
|
|
|
return modeA.rotationIsDir;
|
|
|
|
}
|
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
void CCParticleSystem::setGravity(const CCPoint& g)
|
2010-12-27 17:39:15 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
CCAssert( _emitterMode == kCCParticleModeGravity, "Particle Mode should be Gravity");
|
2012-04-19 14:35:52 +08:00
|
|
|
modeA.gravity = g;
|
2010-12-27 17:39:15 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
const CCPoint& CCParticleSystem::getGravity()
|
2010-12-27 17:39:15 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
CCAssert( _emitterMode == kCCParticleModeGravity, "Particle Mode should be Gravity");
|
2012-04-19 14:35:52 +08:00
|
|
|
return modeA.gravity;
|
2010-12-27 17:39:15 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2010-12-27 17:39:15 +08:00
|
|
|
void CCParticleSystem::setSpeed(float speed)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
CCAssert( _emitterMode == kCCParticleModeGravity, "Particle Mode should be Gravity");
|
2012-04-19 14:35:52 +08:00
|
|
|
modeA.speed = speed;
|
2010-12-27 17:39:15 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2010-12-27 17:39:15 +08:00
|
|
|
float CCParticleSystem::getSpeed()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
CCAssert( _emitterMode == kCCParticleModeGravity, "Particle Mode should be Gravity");
|
2012-04-19 14:35:52 +08:00
|
|
|
return modeA.speed;
|
2010-12-27 17:39:15 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2010-12-27 17:39:15 +08:00
|
|
|
void CCParticleSystem::setSpeedVar(float speedVar)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
CCAssert( _emitterMode == kCCParticleModeGravity, "Particle Mode should be Gravity");
|
2012-04-19 14:35:52 +08:00
|
|
|
modeA.speedVar = speedVar;
|
2010-12-27 17:39:15 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2010-12-27 17:39:15 +08:00
|
|
|
float CCParticleSystem::getSpeedVar()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
CCAssert( _emitterMode == kCCParticleModeGravity, "Particle Mode should be Gravity");
|
2012-04-19 14:35:52 +08:00
|
|
|
return modeA.speedVar;
|
2010-12-27 17:39:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// ParticleSystem - Properties of Radius Mode
|
|
|
|
void CCParticleSystem::setStartRadius(float startRadius)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
CCAssert( _emitterMode == kCCParticleModeRadius, "Particle Mode should be Radius");
|
2012-04-19 14:35:52 +08:00
|
|
|
modeB.startRadius = startRadius;
|
2010-12-27 17:39:15 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2010-12-27 17:39:15 +08:00
|
|
|
float CCParticleSystem::getStartRadius()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
CCAssert( _emitterMode == kCCParticleModeRadius, "Particle Mode should be Radius");
|
2012-04-19 14:35:52 +08:00
|
|
|
return modeB.startRadius;
|
2010-12-27 17:39:15 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2010-12-27 17:39:15 +08:00
|
|
|
void CCParticleSystem::setStartRadiusVar(float startRadiusVar)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
CCAssert( _emitterMode == kCCParticleModeRadius, "Particle Mode should be Radius");
|
2012-04-19 14:35:52 +08:00
|
|
|
modeB.startRadiusVar = startRadiusVar;
|
2010-12-27 17:39:15 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2010-12-27 17:39:15 +08:00
|
|
|
float CCParticleSystem::getStartRadiusVar()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
CCAssert( _emitterMode == kCCParticleModeRadius, "Particle Mode should be Radius");
|
2012-04-19 14:35:52 +08:00
|
|
|
return modeB.startRadiusVar;
|
2010-12-27 17:39:15 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2010-12-27 17:39:15 +08:00
|
|
|
void CCParticleSystem::setEndRadius(float endRadius)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
CCAssert( _emitterMode == kCCParticleModeRadius, "Particle Mode should be Radius");
|
2012-04-19 14:35:52 +08:00
|
|
|
modeB.endRadius = endRadius;
|
2010-12-27 17:39:15 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2010-12-27 17:39:15 +08:00
|
|
|
float CCParticleSystem::getEndRadius()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
CCAssert( _emitterMode == kCCParticleModeRadius, "Particle Mode should be Radius");
|
2012-04-19 14:35:52 +08:00
|
|
|
return modeB.endRadius;
|
2010-12-27 17:39:15 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2010-12-27 17:39:15 +08:00
|
|
|
void CCParticleSystem::setEndRadiusVar(float endRadiusVar)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
CCAssert( _emitterMode == kCCParticleModeRadius, "Particle Mode should be Radius");
|
2012-04-19 14:35:52 +08:00
|
|
|
modeB.endRadiusVar = endRadiusVar;
|
2010-12-27 17:39:15 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2010-12-27 17:39:15 +08:00
|
|
|
float CCParticleSystem::getEndRadiusVar()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
CCAssert( _emitterMode == kCCParticleModeRadius, "Particle Mode should be Radius");
|
2012-04-19 14:35:52 +08:00
|
|
|
return modeB.endRadiusVar;
|
2010-12-27 17:39:15 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2010-12-27 17:39:15 +08:00
|
|
|
void CCParticleSystem::setRotatePerSecond(float degrees)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
CCAssert( _emitterMode == kCCParticleModeRadius, "Particle Mode should be Radius");
|
2012-04-19 14:35:52 +08:00
|
|
|
modeB.rotatePerSecond = degrees;
|
2010-12-27 17:39:15 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2010-12-27 17:39:15 +08:00
|
|
|
float CCParticleSystem::getRotatePerSecond()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
CCAssert( _emitterMode == kCCParticleModeRadius, "Particle Mode should be Radius");
|
2012-04-19 14:35:52 +08:00
|
|
|
return modeB.rotatePerSecond;
|
2010-12-27 17:39:15 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2010-12-27 17:39:15 +08:00
|
|
|
void CCParticleSystem::setRotatePerSecondVar(float degrees)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
CCAssert( _emitterMode == kCCParticleModeRadius, "Particle Mode should be Radius");
|
2012-04-19 14:35:52 +08:00
|
|
|
modeB.rotatePerSecondVar = degrees;
|
2010-12-27 17:39:15 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2010-12-27 17:39:15 +08:00
|
|
|
float CCParticleSystem::getRotatePerSecondVar()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
CCAssert( _emitterMode == kCCParticleModeRadius, "Particle Mode should be Radius");
|
2012-04-19 14:35:52 +08:00
|
|
|
return modeB.rotatePerSecondVar;
|
2010-12-27 17:39:15 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2012-06-15 15:10:40 +08:00
|
|
|
bool CCParticleSystem::isActive()
|
2011-03-19 10:07:16 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _isActive;
|
2011-03-19 10:07:16 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2013-06-14 08:25:14 +08:00
|
|
|
unsigned int CCParticleSystem::getParticleCount() const
|
2011-03-19 10:07:16 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _particleCount;
|
2011-03-19 10:07:16 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2011-03-19 10:07:16 +08:00
|
|
|
float CCParticleSystem::getDuration()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _duration;
|
2011-03-19 10:07:16 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2011-03-19 10:07:16 +08:00
|
|
|
void CCParticleSystem::setDuration(float var)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_duration = var;
|
2011-03-19 10:07:16 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2013-01-14 15:51:53 +08:00
|
|
|
const CCPoint& CCParticleSystem::getSourcePosition()
|
2011-03-19 10:07:16 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _sourcePosition;
|
2011-03-19 10:07:16 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
void CCParticleSystem::setSourcePosition(const CCPoint& var)
|
2011-03-19 10:07:16 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_sourcePosition = var;
|
2011-03-19 10:07:16 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2013-01-14 15:51:53 +08:00
|
|
|
const CCPoint& CCParticleSystem::getPosVar()
|
2011-03-19 10:07:16 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _posVar;
|
2011-03-19 10:07:16 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
void CCParticleSystem::setPosVar(const CCPoint& var)
|
2011-03-19 10:07:16 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_posVar = var;
|
2011-03-19 10:07:16 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2011-03-19 10:07:16 +08:00
|
|
|
float CCParticleSystem::getLife()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _life;
|
2011-03-19 10:07:16 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2011-03-19 10:07:16 +08:00
|
|
|
void CCParticleSystem::setLife(float var)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_life = var;
|
2011-03-19 10:07:16 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2011-03-19 10:07:16 +08:00
|
|
|
float CCParticleSystem::getLifeVar()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _lifeVar;
|
2011-03-19 10:07:16 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2011-03-19 10:07:16 +08:00
|
|
|
void CCParticleSystem::setLifeVar(float var)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_lifeVar = var;
|
2011-03-19 10:07:16 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2011-03-19 10:07:16 +08:00
|
|
|
float CCParticleSystem::getAngle()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _angle;
|
2011-03-19 10:07:16 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2011-03-19 10:07:16 +08:00
|
|
|
void CCParticleSystem::setAngle(float var)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_angle = var;
|
2011-03-19 10:07:16 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2011-03-19 10:07:16 +08:00
|
|
|
float CCParticleSystem::getAngleVar()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _angleVar;
|
2011-03-19 10:07:16 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2011-03-19 10:07:16 +08:00
|
|
|
void CCParticleSystem::setAngleVar(float var)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_angleVar = var;
|
2011-03-19 10:07:16 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2011-03-19 10:07:16 +08:00
|
|
|
float CCParticleSystem::getStartSize()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _startSize;
|
2011-03-19 10:07:16 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2011-03-19 10:07:16 +08:00
|
|
|
void CCParticleSystem::setStartSize(float var)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_startSize = var;
|
2011-03-19 10:07:16 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2011-03-19 10:07:16 +08:00
|
|
|
float CCParticleSystem::getStartSizeVar()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _startSizeVar;
|
2011-03-19 10:07:16 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2011-03-19 10:07:16 +08:00
|
|
|
void CCParticleSystem::setStartSizeVar(float var)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_startSizeVar = var;
|
2011-03-19 10:07:16 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2011-03-19 10:07:16 +08:00
|
|
|
float CCParticleSystem::getEndSize()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _endSize;
|
2011-03-19 10:07:16 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2011-03-19 10:07:16 +08:00
|
|
|
void CCParticleSystem::setEndSize(float var)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_endSize = var;
|
2011-03-19 10:07:16 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2011-03-19 10:07:16 +08:00
|
|
|
float CCParticleSystem::getEndSizeVar()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _endSizeVar;
|
2011-03-19 10:07:16 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2011-03-19 10:07:16 +08:00
|
|
|
void CCParticleSystem::setEndSizeVar(float var)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_endSizeVar = var;
|
2011-03-19 10:07:16 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2013-01-14 15:51:53 +08:00
|
|
|
const ccColor4F& CCParticleSystem::getStartColor()
|
2011-03-19 10:07:16 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _startColor;
|
2011-03-19 10:07:16 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
void CCParticleSystem::setStartColor(const ccColor4F& var)
|
2011-03-19 10:07:16 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_startColor = var;
|
2011-03-19 10:07:16 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2013-01-14 15:51:53 +08:00
|
|
|
const ccColor4F& CCParticleSystem::getStartColorVar()
|
2011-03-19 10:07:16 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _startColorVar;
|
2011-03-19 10:07:16 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
void CCParticleSystem::setStartColorVar(const ccColor4F& var)
|
2011-03-19 10:07:16 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_startColorVar = var;
|
2011-03-19 10:07:16 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2013-01-14 15:51:53 +08:00
|
|
|
const ccColor4F& CCParticleSystem::getEndColor()
|
2011-03-19 10:07:16 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _endColor;
|
2011-03-19 10:07:16 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
void CCParticleSystem::setEndColor(const ccColor4F& var)
|
2011-03-19 10:07:16 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_endColor = var;
|
2011-03-19 10:07:16 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2013-01-14 15:51:53 +08:00
|
|
|
const ccColor4F& CCParticleSystem::getEndColorVar()
|
2011-03-19 10:07:16 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _endColorVar;
|
2011-03-19 10:07:16 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2011-08-17 21:19:57 +08:00
|
|
|
void CCParticleSystem::setEndColorVar(const ccColor4F& var)
|
2011-03-19 10:07:16 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_endColorVar = var;
|
2011-03-19 10:07:16 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2011-03-19 10:07:16 +08:00
|
|
|
float CCParticleSystem::getStartSpin()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _startSpin;
|
2011-03-19 10:07:16 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2011-03-19 10:07:16 +08:00
|
|
|
void CCParticleSystem::setStartSpin(float var)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_startSpin = var;
|
2011-03-19 10:07:16 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2011-03-19 10:07:16 +08:00
|
|
|
float CCParticleSystem::getStartSpinVar()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _startSpinVar;
|
2011-03-19 10:07:16 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2011-03-19 10:07:16 +08:00
|
|
|
void CCParticleSystem::setStartSpinVar(float var)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_startSpinVar = var;
|
2011-03-19 10:07:16 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2011-03-19 10:07:16 +08:00
|
|
|
float CCParticleSystem::getEndSpin()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _endSpin;
|
2011-03-19 10:07:16 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2011-03-19 10:07:16 +08:00
|
|
|
void CCParticleSystem::setEndSpin(float var)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_endSpin = var;
|
2011-03-19 10:07:16 +08:00
|
|
|
}
|
|
|
|
float CCParticleSystem::getEndSpinVar()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _endSpinVar;
|
2011-03-19 10:07:16 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2011-03-19 10:07:16 +08:00
|
|
|
void CCParticleSystem::setEndSpinVar(float var)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_endSpinVar = var;
|
2011-03-19 10:07:16 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2011-03-19 10:07:16 +08:00
|
|
|
float CCParticleSystem::getEmissionRate()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _emissionRate;
|
2011-03-19 10:07:16 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2011-03-19 10:07:16 +08:00
|
|
|
void CCParticleSystem::setEmissionRate(float var)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_emissionRate = var;
|
2011-03-19 10:07:16 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2011-07-06 18:16:19 +08:00
|
|
|
unsigned int CCParticleSystem::getTotalParticles()
|
2011-03-19 10:07:16 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _totalParticles;
|
2011-03-19 10:07:16 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2011-07-06 18:16:19 +08:00
|
|
|
void CCParticleSystem::setTotalParticles(unsigned int var)
|
2011-03-19 10:07:16 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
CCAssert( var <= _allocatedParticles, "Particle: resizing particle array only supported for quads");
|
|
|
|
_totalParticles = var;
|
2011-03-19 10:07:16 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2011-03-19 10:07:16 +08:00
|
|
|
ccBlendFunc CCParticleSystem::getBlendFunc()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _blendFunc;
|
2011-03-19 10:07:16 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2012-06-08 14:11:48 +08:00
|
|
|
void CCParticleSystem::setBlendFunc(ccBlendFunc blendFunc)
|
2011-03-19 10:07:16 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if( _blendFunc.src != blendFunc.src || _blendFunc.dst != blendFunc.dst ) {
|
|
|
|
_blendFunc = blendFunc;
|
2012-06-12 01:43:07 +08:00
|
|
|
this->updateBlendFunc();
|
2012-06-08 14:11:48 +08:00
|
|
|
}
|
2011-03-19 10:07:16 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2012-06-08 16:54:38 +08:00
|
|
|
bool CCParticleSystem::getOpacityModifyRGB()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _opacityModifyRGB;
|
2012-06-08 16:54:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCParticleSystem::setOpacityModifyRGB(bool bOpacityModifyRGB)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_opacityModifyRGB = bOpacityModifyRGB;
|
2012-06-08 16:54:38 +08:00
|
|
|
}
|
|
|
|
|
2011-03-19 10:07:16 +08:00
|
|
|
tCCPositionType CCParticleSystem::getPositionType()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _positionType;
|
2011-03-19 10:07:16 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2011-03-19 10:07:16 +08:00
|
|
|
void CCParticleSystem::setPositionType(tCCPositionType var)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_positionType = var;
|
2011-03-19 10:07:16 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2012-06-15 16:47:30 +08:00
|
|
|
bool CCParticleSystem::isAutoRemoveOnFinish()
|
2011-03-19 10:07:16 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _isAutoRemoveOnFinish;
|
2011-03-19 10:07:16 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2012-06-15 16:47:30 +08:00
|
|
|
void CCParticleSystem::setAutoRemoveOnFinish(bool var)
|
2011-03-19 10:07:16 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_isAutoRemoveOnFinish = var;
|
2011-03-19 10:07:16 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2011-03-19 10:07:16 +08:00
|
|
|
int CCParticleSystem::getEmitterMode()
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _emitterMode;
|
2011-03-19 10:07:16 +08:00
|
|
|
}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2011-03-19 10:07:16 +08:00
|
|
|
void CCParticleSystem::setEmitterMode(int var)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_emitterMode = var;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// ParticleSystem - methods for batchNode rendering
|
|
|
|
|
|
|
|
CCParticleBatchNode* CCParticleSystem::getBatchNode(void)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _batchNode;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void CCParticleSystem::setBatchNode(CCParticleBatchNode* batchNode)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if( _batchNode != batchNode ) {
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_batchNode = batchNode; // weak reference
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
if( batchNode ) {
|
|
|
|
//each particle needs a unique index
|
2013-06-15 14:03:30 +08:00
|
|
|
for (unsigned int i = 0; i < _totalParticles; i++)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_particles[i].atlasIndex=i;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//don't use a transform matrix, this is faster
|
|
|
|
void CCParticleSystem::setScale(float s)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_transformSystemDirty = true;
|
2012-04-19 14:35:52 +08:00
|
|
|
CCNode::setScale(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCParticleSystem::setRotation(float newRotation)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_transformSystemDirty = true;
|
2012-04-19 14:35:52 +08:00
|
|
|
CCNode::setRotation(newRotation);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCParticleSystem::setScaleX(float newScaleX)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_transformSystemDirty = true;
|
2012-04-19 14:35:52 +08:00
|
|
|
CCNode::setScaleX(newScaleX);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CCParticleSystem::setScaleY(float newScaleY)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_transformSystemDirty = true;
|
2012-04-19 14:35:52 +08:00
|
|
|
CCNode::setScaleY(newScaleY);
|
|
|
|
}
|
2012-03-14 14:55:17 +08:00
|
|
|
|
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
NS_CC_END
|
2010-12-28 10:23:14 +08:00
|
|
|
|