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.
|
2016-08-05 09:42:15 +08:00
|
|
|
Copyright (c) 2013-2016 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.
|
|
|
|
****************************************************************************/
|
|
|
|
#ifndef __CCPARTICLE_SYSTEM_H__
|
|
|
|
#define __CCPARTICLE_SYSTEM_H__
|
2010-08-23 14:57:37 +08:00
|
|
|
|
2014-05-17 05:36:00 +08:00
|
|
|
#include "base/CCProtocols.h"
|
2014-04-27 01:11:22 +08:00
|
|
|
#include "2d/CCNode.h"
|
2014-04-27 01:35:57 +08:00
|
|
|
#include "base/CCValue.h"
|
2010-08-25 14:37:40 +08:00
|
|
|
|
2012-03-20 15:04:53 +08:00
|
|
|
NS_CC_BEGIN
|
2010-08-23 14:57:37 +08:00
|
|
|
|
2012-06-20 18:09:11 +08:00
|
|
|
/**
|
2015-03-24 10:34:41 +08:00
|
|
|
* @addtogroup _2d
|
2012-06-20 18:09:11 +08:00
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
class ParticleBatchNode;
|
2010-08-23 14:57:37 +08:00
|
|
|
|
2015-03-21 18:02:56 +08:00
|
|
|
/** @struct sParticle
|
|
|
|
Structure that contains the values of each particle.
|
2010-12-27 17:39:15 +08:00
|
|
|
*/
|
|
|
|
|
2015-08-31 17:25:34 +08:00
|
|
|
struct particle_point
|
|
|
|
{
|
|
|
|
float x;
|
|
|
|
float y;
|
|
|
|
};
|
2012-03-14 14:55:17 +08:00
|
|
|
|
2015-08-31 17:25:34 +08:00
|
|
|
class CC_DLL ParticleData
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
float* posx;
|
|
|
|
float* posy;
|
|
|
|
float* startPosX;
|
|
|
|
float* startPosY;
|
|
|
|
|
|
|
|
float* colorR;
|
|
|
|
float* colorG;
|
|
|
|
float* colorB;
|
|
|
|
float* colorA;
|
|
|
|
|
|
|
|
float* deltaColorR;
|
|
|
|
float* deltaColorG;
|
|
|
|
float* deltaColorB;
|
|
|
|
float* deltaColorA;
|
|
|
|
|
|
|
|
float* size;
|
|
|
|
float* deltaSize;
|
|
|
|
float* rotation;
|
|
|
|
float* deltaRotation;
|
|
|
|
float* timeToLive;
|
|
|
|
unsigned int* atlasIndex;
|
|
|
|
|
|
|
|
//! Mode A: gravity, direction, radial accel, tangential accel
|
|
|
|
struct{
|
|
|
|
float* dirX;
|
|
|
|
float* dirY;
|
|
|
|
float* radialAccel;
|
|
|
|
float* tangentialAccel;
|
2012-04-19 14:35:52 +08:00
|
|
|
} modeA;
|
2015-08-31 17:25:34 +08:00
|
|
|
|
|
|
|
//! Mode B: radius mode
|
|
|
|
struct{
|
|
|
|
float* angle;
|
|
|
|
float* degreesPerSecond;
|
|
|
|
float* radius;
|
|
|
|
float* deltaRadius;
|
2012-04-19 14:35:52 +08:00
|
|
|
} modeB;
|
2015-08-31 17:25:34 +08:00
|
|
|
|
|
|
|
unsigned int maxCount;
|
|
|
|
ParticleData();
|
|
|
|
bool init(int count);
|
|
|
|
void release();
|
2016-09-12 09:44:21 +08:00
|
|
|
unsigned int getMaxCount() { return maxCount; }
|
2015-08-31 17:25:34 +08:00
|
|
|
|
2016-09-12 09:44:21 +08:00
|
|
|
void copyParticle(int p1, int p2)
|
2015-08-31 17:25:34 +08:00
|
|
|
{
|
|
|
|
posx[p1] = posx[p2];
|
|
|
|
posy[p1] = posy[p2];
|
|
|
|
startPosX[p1] = startPosX[p2];
|
|
|
|
startPosY[p1] = startPosY[p2];
|
|
|
|
|
|
|
|
colorR[p1] = colorR[p2];
|
|
|
|
colorG[p1] = colorG[p2];
|
|
|
|
colorB[p1] = colorB[p2];
|
|
|
|
colorA[p1] = colorA[p2];
|
|
|
|
|
|
|
|
deltaColorR[p1] = deltaColorR[p2];
|
|
|
|
deltaColorG[p1] = deltaColorG[p2];
|
|
|
|
deltaColorB[p1] = deltaColorB[p2];
|
|
|
|
deltaColorA[p1] = deltaColorA[p2];
|
|
|
|
|
|
|
|
size[p1] = size[p2];
|
|
|
|
deltaSize[p1] = deltaSize[p2];
|
|
|
|
|
|
|
|
rotation[p1] = rotation[p2];
|
|
|
|
deltaRotation[p1] = deltaRotation[p2];
|
|
|
|
|
|
|
|
timeToLive[p1] = timeToLive[p2];
|
|
|
|
|
|
|
|
atlasIndex[p1] = atlasIndex[p2];
|
|
|
|
|
|
|
|
modeA.dirX[p1] = modeA.dirX[p2];
|
|
|
|
modeA.dirY[p1] = modeA.dirY[p2];
|
|
|
|
modeA.radialAccel[p1] = modeA.radialAccel[p2];
|
|
|
|
modeA.tangentialAccel[p1] = modeA.tangentialAccel[p2];
|
|
|
|
|
|
|
|
modeB.angle[p1] = modeB.angle[p2];
|
|
|
|
modeB.degreesPerSecond[p1] = modeB.degreesPerSecond[p2];
|
|
|
|
modeB.radius[p1] = modeB.radius[p2];
|
|
|
|
modeB.deltaRadius[p1] = modeB.deltaRadius[p2];
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-12-27 17:39:15 +08:00
|
|
|
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
//typedef void (*CC_UPDATE_PARTICLE_IMP)(id, SEL, tParticle*, Vec2);
|
2010-12-27 17:39:15 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
class Texture2D;
|
2010-12-27 17:39:15 +08:00
|
|
|
|
2015-03-21 18:02:56 +08:00
|
|
|
/** @class ParticleSystem
|
|
|
|
* @brief Particle System base class.
|
2010-12-27 17:39:15 +08:00
|
|
|
Attributes of a Particle System:
|
2012-09-17 15:02:24 +08:00
|
|
|
- emission rate of the particles
|
2010-12-27 17:39:15 +08:00
|
|
|
- Gravity Mode (Mode A):
|
|
|
|
- gravity
|
|
|
|
- direction
|
|
|
|
- speed +- variance
|
|
|
|
- tangential acceleration +- variance
|
|
|
|
- radial acceleration +- variance
|
|
|
|
- Radius Mode (Mode B):
|
|
|
|
- startRadius +- variance
|
|
|
|
- endRadius +- variance
|
|
|
|
- rotate +- variance
|
|
|
|
- Properties common to all modes:
|
|
|
|
- life +- life variance
|
|
|
|
- start spin +- variance
|
|
|
|
- end spin +- variance
|
|
|
|
- start size +- variance
|
|
|
|
- end size +- variance
|
|
|
|
- start color +- variance
|
|
|
|
- end color +- variance
|
|
|
|
- life +- variance
|
|
|
|
- blending function
|
|
|
|
- texture
|
|
|
|
|
2015-03-21 18:02:56 +08:00
|
|
|
Cocos2d also supports particles generated by Particle Designer (http://particledesigner.71squared.com/).
|
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.
|
|
|
|
|
2015-03-21 18:02:56 +08:00
|
|
|
Cocos2d supports all the variables used by Particle Designer plus a bit more:
|
2013-06-20 14:13:12 +08:00
|
|
|
- spinning particles (supported when using ParticleSystemQuad)
|
2010-12-27 17:39:15 +08:00
|
|
|
- tangential acceleration (Gravity mode)
|
|
|
|
- radial acceleration (Gravity mode)
|
|
|
|
- radius direction (Radius mode) (Particle Designer supports outwards to inwards direction only)
|
|
|
|
|
|
|
|
It is possible to customize any of the above mentioned properties in runtime. Example:
|
|
|
|
|
|
|
|
@code
|
|
|
|
emitter.radialAccel = 15;
|
|
|
|
emitter.startSpin = 0;
|
|
|
|
@endcode
|
|
|
|
|
|
|
|
*/
|
2014-03-22 21:09:16 +08:00
|
|
|
|
2015-05-09 00:19:13 +08:00
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT)
|
2014-03-22 21:09:16 +08:00
|
|
|
#ifdef RELATIVE
|
|
|
|
#undef RELATIVE
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2016-01-12 17:21:01 +08:00
|
|
|
class CC_DLL ParticleSystem : public Node, public TextureProtocol, public PlayableProtocol
|
2013-07-18 07:56:19 +08:00
|
|
|
{
|
|
|
|
public:
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Mode
|
2015-03-23 20:27:13 +08:00
|
|
|
* @js cc.ParticleSystem.MODE_GRAVITY;
|
2015-03-21 18:02:56 +08:00
|
|
|
*/
|
2013-07-26 13:48:32 +08:00
|
|
|
enum class Mode
|
2013-07-25 13:54:32 +08:00
|
|
|
{
|
2013-07-26 13:48:32 +08:00
|
|
|
GRAVITY,
|
|
|
|
RADIUS,
|
2013-07-25 13:54:32 +08:00
|
|
|
};
|
|
|
|
|
2015-03-21 18:02:56 +08:00
|
|
|
/** PositionType
|
|
|
|
Possible types of particle positions.
|
2015-03-23 20:27:13 +08:00
|
|
|
* @js cc.ParticleSystem.TYPE_FREE
|
2013-07-25 14:27:46 +08:00
|
|
|
*/
|
2013-07-26 13:48:32 +08:00
|
|
|
enum class PositionType
|
2013-07-25 14:27:46 +08:00
|
|
|
{
|
2015-03-21 18:02:56 +08:00
|
|
|
FREE, /** Living particles are attached to the world and are unaffected by emitter repositioning. */
|
2013-07-25 14:27:46 +08:00
|
|
|
|
2015-03-21 18:02:56 +08:00
|
|
|
RELATIVE, /** Living particles are attached to the world but will follow the emitter repositioning.
|
|
|
|
Use case: Attach an emitter to an sprite, and you want that the emitter follows the sprite.*/
|
2013-07-25 14:27:46 +08:00
|
|
|
|
2015-03-21 18:02:56 +08:00
|
|
|
GROUPED, /** Living particles are attached to the emitter and are translated along with it. */
|
|
|
|
|
2013-07-25 14:27:46 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
//* @enum
|
|
|
|
enum {
|
2015-03-21 18:02:56 +08:00
|
|
|
/** The Particle emitter lives forever. */
|
2013-07-25 14:27:46 +08:00
|
|
|
DURATION_INFINITY = -1,
|
|
|
|
|
2015-03-21 18:02:56 +08:00
|
|
|
/** The starting size of the particle is equal to the ending size. */
|
2013-07-25 14:27:46 +08:00
|
|
|
START_SIZE_EQUAL_TO_END_SIZE = -1,
|
|
|
|
|
2015-03-21 18:02:56 +08:00
|
|
|
/** The starting radius of the particle is equal to the ending radius. */
|
2013-07-25 14:27:46 +08:00
|
|
|
START_RADIUS_EQUAL_TO_END_RADIUS = -1,
|
|
|
|
};
|
|
|
|
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Creates an initializes a ParticleSystem from a plist file.
|
2013-07-18 07:56:19 +08:00
|
|
|
This plist files can be created manually or with Particle Designer:
|
|
|
|
http://particledesigner.71squared.com/
|
2015-03-21 18:02:56 +08:00
|
|
|
@since v2.0
|
|
|
|
*
|
2015-03-27 12:07:19 +08:00
|
|
|
* @param plistFile Particle plist file name.
|
2015-03-21 18:02:56 +08:00
|
|
|
* @return An autoreleased ParticleSystem object.
|
|
|
|
*/
|
2013-11-06 11:02:03 +08:00
|
|
|
static ParticleSystem * create(const std::string& plistFile);
|
2013-07-18 07:56:19 +08:00
|
|
|
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Create a system with a fixed number of particles.
|
|
|
|
*
|
|
|
|
* @param numberOfParticles A given number of particles.
|
|
|
|
* @return An autoreleased ParticleSystemQuad object.
|
2015-03-23 20:27:13 +08:00
|
|
|
* @js NA
|
2015-03-21 18:02:56 +08:00
|
|
|
*/
|
2013-11-15 08:21:49 +08:00
|
|
|
static ParticleSystem* createWithTotalParticles(int numberOfParticles);
|
2015-08-31 17:25:34 +08:00
|
|
|
|
|
|
|
void addParticles(int count);
|
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
void stopSystem();
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Kill all living particles.
|
|
|
|
*/
|
2013-07-18 07:56:19 +08:00
|
|
|
void resetSystem();
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Whether or not the system is full.
|
|
|
|
*
|
|
|
|
* @return True if the system is full.
|
|
|
|
*/
|
2013-07-18 07:56:19 +08:00
|
|
|
bool isFull();
|
|
|
|
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Update the verts position data of particle,
|
|
|
|
should be overridden by subclasses.
|
|
|
|
*/
|
2015-08-31 17:25:34 +08:00
|
|
|
virtual void updateParticleQuads();
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Update the VBO verts buffer which does not use batch node,
|
|
|
|
should be overridden by subclasses. */
|
2013-07-18 07:56:19 +08:00
|
|
|
virtual void postStep();
|
|
|
|
|
2015-09-22 16:08:23 +08:00
|
|
|
/** Call the update method with no time..
|
2015-03-21 18:02:56 +08:00
|
|
|
*/
|
2015-03-27 12:07:19 +08:00
|
|
|
virtual void updateWithNoTime();
|
2013-07-18 07:56:19 +08:00
|
|
|
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Whether or not the particle system removed self on finish.
|
|
|
|
*
|
|
|
|
* @return True if the particle system removed self on finish.
|
|
|
|
*/
|
2013-07-18 07:56:19 +08:00
|
|
|
virtual bool isAutoRemoveOnFinish() const;
|
2015-03-21 18:02:56 +08:00
|
|
|
|
|
|
|
/** Set the particle system auto removed it self on finish.
|
|
|
|
*
|
|
|
|
* @param var True if the particle system removed self on finish.
|
|
|
|
*/
|
2013-07-18 07:56:19 +08:00
|
|
|
virtual void setAutoRemoveOnFinish(bool var);
|
|
|
|
|
|
|
|
// mode A
|
2015-09-22 16:08:23 +08:00
|
|
|
/** Gets the gravity.
|
2015-03-21 18:02:56 +08:00
|
|
|
*
|
|
|
|
* @return The gravity.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
virtual const Vec2& getGravity();
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Sets the gravity.
|
|
|
|
*
|
|
|
|
* @param g The gravity.
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
virtual void setGravity(const Vec2& g);
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Gets the speed.
|
|
|
|
*
|
|
|
|
* @return The speed.
|
|
|
|
*/
|
2013-07-18 07:56:19 +08:00
|
|
|
virtual float getSpeed() const;
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Sets the speed.
|
|
|
|
*
|
|
|
|
* @param speed The speed.
|
|
|
|
*/
|
2013-07-18 07:56:19 +08:00
|
|
|
virtual void setSpeed(float speed);
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Gets the speed variance.
|
|
|
|
*
|
|
|
|
* @return The speed variance.
|
|
|
|
*/
|
2013-07-18 07:56:19 +08:00
|
|
|
virtual float getSpeedVar() const;
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Sets the speed variance.
|
|
|
|
*
|
|
|
|
* @param speed The speed variance.
|
|
|
|
*/
|
2013-07-18 07:56:19 +08:00
|
|
|
virtual void setSpeedVar(float speed);
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Gets the tangential acceleration.
|
|
|
|
*
|
|
|
|
* @return The tangential acceleration.
|
|
|
|
*/
|
2013-07-18 07:56:19 +08:00
|
|
|
virtual float getTangentialAccel() const;
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Sets the tangential acceleration.
|
|
|
|
*
|
|
|
|
* @param t The tangential acceleration.
|
|
|
|
*/
|
2013-07-18 07:56:19 +08:00
|
|
|
virtual void setTangentialAccel(float t);
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Gets the tangential acceleration variance.
|
|
|
|
*
|
|
|
|
* @return The tangential acceleration variance.
|
|
|
|
*/
|
2013-07-18 07:56:19 +08:00
|
|
|
virtual float getTangentialAccelVar() const;
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Sets the tangential acceleration variance.
|
|
|
|
*
|
|
|
|
* @param t The tangential acceleration variance.
|
|
|
|
*/
|
2013-07-18 07:56:19 +08:00
|
|
|
virtual void setTangentialAccelVar(float t);
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Gets the radial acceleration.
|
|
|
|
*
|
|
|
|
* @return The radial acceleration.
|
|
|
|
*/
|
2013-07-18 07:56:19 +08:00
|
|
|
virtual float getRadialAccel() const;
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Sets the radial acceleration.
|
|
|
|
*
|
|
|
|
* @param t The radial acceleration.
|
|
|
|
*/
|
2013-07-18 07:56:19 +08:00
|
|
|
virtual void setRadialAccel(float t);
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Gets the radial acceleration variance.
|
|
|
|
*
|
|
|
|
* @return The radial acceleration variance.
|
|
|
|
*/
|
2013-07-18 07:56:19 +08:00
|
|
|
virtual float getRadialAccelVar() const;
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Sets the radial acceleration variance.
|
|
|
|
*
|
|
|
|
* @param t The radial acceleration variance.
|
|
|
|
*/
|
2013-07-18 07:56:19 +08:00
|
|
|
virtual void setRadialAccelVar(float t);
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Whether or not the rotation of each particle to its direction.
|
|
|
|
*
|
|
|
|
* @return True if the rotation is the direction.
|
|
|
|
*/
|
2013-07-18 07:56:19 +08:00
|
|
|
virtual bool getRotationIsDir() const;
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Sets the rotation of each particle to its direction.
|
|
|
|
*
|
|
|
|
* @param t True if the rotation is the direction.
|
|
|
|
*/
|
2013-07-18 07:56:19 +08:00
|
|
|
virtual void setRotationIsDir(bool t);
|
|
|
|
// mode B
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Gets the start radius.
|
|
|
|
*
|
|
|
|
* @return The start radius.
|
|
|
|
*/
|
2013-07-18 07:56:19 +08:00
|
|
|
virtual float getStartRadius() const;
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Sets the start radius.
|
|
|
|
*
|
|
|
|
* @param startRadius The start radius.
|
|
|
|
*/
|
2013-07-18 07:56:19 +08:00
|
|
|
virtual void setStartRadius(float startRadius);
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Gets the start radius variance.
|
|
|
|
*
|
|
|
|
* @return The start radius variance.
|
|
|
|
*/
|
2013-07-18 07:56:19 +08:00
|
|
|
virtual float getStartRadiusVar() const;
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Sets the start radius variance.
|
|
|
|
*
|
|
|
|
* @param startRadiusVar The start radius variance.
|
|
|
|
*/
|
2013-07-18 07:56:19 +08:00
|
|
|
virtual void setStartRadiusVar(float startRadiusVar);
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Gets the end radius.
|
|
|
|
*
|
|
|
|
* @return The end radius.
|
|
|
|
*/
|
2013-07-18 07:56:19 +08:00
|
|
|
virtual float getEndRadius() const;
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Sets the end radius.
|
|
|
|
*
|
|
|
|
* @param endRadius The end radius.
|
|
|
|
*/
|
2013-07-18 07:56:19 +08:00
|
|
|
virtual void setEndRadius(float endRadius);
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Gets the end radius variance.
|
|
|
|
*
|
|
|
|
* @return The end radius variance.
|
|
|
|
*/
|
2013-07-18 07:56:19 +08:00
|
|
|
virtual float getEndRadiusVar() const;
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Sets the end radius variance.
|
|
|
|
*
|
|
|
|
* @param endRadiusVar The end radius variance.
|
|
|
|
*/
|
2013-07-18 07:56:19 +08:00
|
|
|
virtual void setEndRadiusVar(float endRadiusVar);
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Gets the number of degrees to rotate a particle around the source pos per second.
|
|
|
|
*
|
|
|
|
* @return The number of degrees to rotate a particle around the source pos per second.
|
|
|
|
*/
|
2013-07-18 07:56:19 +08:00
|
|
|
virtual float getRotatePerSecond() const;
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Sets the number of degrees to rotate a particle around the source pos per second.
|
|
|
|
*
|
|
|
|
* @param degrees The number of degrees to rotate a particle around the source pos per second.
|
|
|
|
*/
|
2013-07-18 07:56:19 +08:00
|
|
|
virtual void setRotatePerSecond(float degrees);
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Gets the rotate per second variance.
|
|
|
|
*
|
|
|
|
* @return The rotate per second variance.
|
|
|
|
*/
|
2013-07-18 07:56:19 +08:00
|
|
|
virtual float getRotatePerSecondVar() const;
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Sets the rotate per second variance.
|
|
|
|
*
|
|
|
|
* @param degrees The rotate per second variance.
|
|
|
|
*/
|
2013-07-18 07:56:19 +08:00
|
|
|
virtual void setRotatePerSecondVar(float degrees);
|
|
|
|
|
2015-03-15 02:33:15 +08:00
|
|
|
virtual void setScale(float s) override;
|
|
|
|
virtual void setRotation(float newRotation) override;
|
|
|
|
virtual void setScaleX(float newScaleX) override;
|
|
|
|
virtual void setScaleY(float newScaleY) override;
|
2013-07-18 07:56:19 +08:00
|
|
|
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Whether or not the particle system is active.
|
|
|
|
*
|
|
|
|
* @return True if the particle system is active.
|
|
|
|
*/
|
2013-07-18 07:56:19 +08:00
|
|
|
virtual bool isActive() const;
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Whether or not the particle system is blend additive.
|
|
|
|
*
|
|
|
|
* @return True if the particle system is blend additive.
|
|
|
|
*/
|
2013-07-18 07:56:19 +08:00
|
|
|
virtual bool isBlendAdditive() const;
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Sets the particle system blend additive.
|
|
|
|
*
|
|
|
|
* @param value True if the particle system is blend additive.
|
|
|
|
*/
|
2013-07-18 07:56:19 +08:00
|
|
|
virtual void setBlendAdditive(bool value);
|
|
|
|
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Gets the batch node.
|
|
|
|
*
|
|
|
|
* @return The batch node.
|
|
|
|
*/
|
2013-07-23 18:26:26 +08:00
|
|
|
virtual ParticleBatchNode* getBatchNode() const;
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Sets the batch node.
|
|
|
|
*
|
|
|
|
* @param batchNode The batch node.
|
|
|
|
*/
|
2013-07-23 18:26:26 +08:00
|
|
|
virtual void setBatchNode(ParticleBatchNode* batchNode);
|
|
|
|
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Gets the index of system in batch node array.
|
|
|
|
*
|
|
|
|
* @return The index of system in batch node array.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
int getAtlasIndex() const { return _atlasIndex; }
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Sets the index of system in batch node array.
|
|
|
|
*
|
|
|
|
* @param index The index of system in batch node array.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
void setAtlasIndex(int index) { _atlasIndex = index; }
|
2013-07-23 18:26:26 +08:00
|
|
|
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Gets the Quantity of particles that are being simulated at the moment.
|
|
|
|
*
|
|
|
|
* @return The Quantity of particles that are being simulated at the moment.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
unsigned int getParticleCount() const { return _particleCount; }
|
2013-07-23 18:26:26 +08:00
|
|
|
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Gets how many seconds the emitter will run. -1 means 'forever'.
|
|
|
|
*
|
|
|
|
* @return The seconds that the emitter will run. -1 means 'forever'.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
float getDuration() const { return _duration; }
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Sets how many seconds the emitter will run. -1 means 'forever'.
|
|
|
|
*
|
|
|
|
* @param duration The seconds that the emitter will run. -1 means 'forever'.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
void setDuration(float duration) { _duration = duration; }
|
2013-07-23 18:26:26 +08:00
|
|
|
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Gets the source position of the emitter.
|
|
|
|
*
|
|
|
|
* @return The source position of the emitter.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
const Vec2& getSourcePosition() const { return _sourcePosition; }
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Sets the source position of the emitter.
|
|
|
|
*
|
2015-03-27 12:07:19 +08:00
|
|
|
* @param pos The source position of the emitter.
|
2015-03-21 18:02:56 +08:00
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
void setSourcePosition(const Vec2& pos) { _sourcePosition = pos; }
|
2013-07-23 18:26:26 +08:00
|
|
|
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Gets the position variance of the emitter.
|
|
|
|
*
|
|
|
|
* @return The position variance of the emitter.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
const Vec2& getPosVar() const { return _posVar; }
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Sets the position variance of the emitter.
|
|
|
|
*
|
|
|
|
* @param pos The position variance of the emitter.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
void setPosVar(const Vec2& pos) { _posVar = pos; }
|
2013-07-23 18:26:26 +08:00
|
|
|
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Gets the life of each particle.
|
|
|
|
*
|
|
|
|
* @return The life of each particle.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
float getLife() const { return _life; }
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Sets the life of each particle.
|
|
|
|
*
|
|
|
|
* @param life The life of each particle.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
void setLife(float life) { _life = life; }
|
2013-07-23 18:26:26 +08:00
|
|
|
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Gets the life variance of each particle.
|
|
|
|
*
|
|
|
|
* @return The life variance of each particle.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
float getLifeVar() const { return _lifeVar; }
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Sets the life variance of each particle.
|
|
|
|
*
|
|
|
|
* @param lifeVar The life variance of each particle.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
void setLifeVar(float lifeVar) { _lifeVar = lifeVar; }
|
2013-07-23 18:26:26 +08:00
|
|
|
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Gets the angle of each particle.
|
|
|
|
*
|
|
|
|
* @return The angle of each particle.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
float getAngle() const { return _angle; }
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Sets the angle of each particle.
|
|
|
|
*
|
|
|
|
* @param angle The angle of each particle.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
void setAngle(float angle) { _angle = angle; }
|
2013-07-23 18:26:26 +08:00
|
|
|
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Gets the angle variance of each particle.
|
|
|
|
*
|
|
|
|
* @return The angle variance of each particle.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
float getAngleVar() const { return _angleVar; }
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Sets the angle variance of each particle.
|
|
|
|
*
|
|
|
|
* @param angleVar The angle variance of each particle.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
void setAngleVar(float angleVar) { _angleVar = angleVar; }
|
2013-07-23 18:26:26 +08:00
|
|
|
|
|
|
|
/** Switch between different kind of emitter modes:
|
2015-03-21 18:02:56 +08:00
|
|
|
- kParticleModeGravity: uses gravity, speed, radial and tangential acceleration.
|
|
|
|
- kParticleModeRadius: uses radius movement + rotation.
|
|
|
|
*
|
|
|
|
* @return The mode of the emitter.
|
2013-07-23 18:26:26 +08:00
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
Mode getEmitterMode() const { return _emitterMode; }
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Sets the mode of the emitter.
|
|
|
|
*
|
|
|
|
* @param mode The mode of the emitter.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
void setEmitterMode(Mode mode) { _emitterMode = mode; }
|
2013-07-23 18:26:26 +08:00
|
|
|
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Gets the start size in pixels of each particle.
|
|
|
|
*
|
|
|
|
* @return The start size in pixels of each particle.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
float getStartSize() const { return _startSize; }
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Sets the start size in pixels of each particle.
|
|
|
|
*
|
|
|
|
* @param startSize The start size in pixels of each particle.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
void setStartSize(float startSize) { _startSize = startSize; }
|
2013-07-23 18:26:26 +08:00
|
|
|
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Gets the start size variance in pixels of each particle.
|
|
|
|
*
|
|
|
|
* @return The start size variance in pixels of each particle.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
float getStartSizeVar() const { return _startSizeVar; }
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Sets the start size variance in pixels of each particle.
|
|
|
|
*
|
|
|
|
* @param sizeVar The start size variance in pixels of each particle.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
void setStartSizeVar(float sizeVar) { _startSizeVar = sizeVar; }
|
2013-07-23 18:26:26 +08:00
|
|
|
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Gets the end size in pixels of each particle.
|
|
|
|
*
|
|
|
|
* @return The end size in pixels of each particle.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
float getEndSize() const { return _endSize; }
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Sets the end size in pixels of each particle.
|
|
|
|
*
|
|
|
|
* @param endSize The end size in pixels of each particle.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
void setEndSize(float endSize) { _endSize = endSize; }
|
2013-07-23 18:26:26 +08:00
|
|
|
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Gets the end size variance in pixels of each particle.
|
|
|
|
*
|
|
|
|
* @return The end size variance in pixels of each particle.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
float getEndSizeVar() const { return _endSizeVar; }
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Sets the end size variance in pixels of each particle.
|
|
|
|
*
|
|
|
|
* @param sizeVar The end size variance in pixels of each particle.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
void setEndSizeVar(float sizeVar) { _endSizeVar = sizeVar; }
|
2013-07-23 18:26:26 +08:00
|
|
|
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Gets the start color of each particle.
|
|
|
|
*
|
|
|
|
* @return The start color of each particle.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
const Color4F& getStartColor() const { return _startColor; }
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Sets the start color of each particle.
|
|
|
|
*
|
|
|
|
* @param color The start color of each particle.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
void setStartColor(const Color4F& color) { _startColor = color; }
|
2013-07-23 18:26:26 +08:00
|
|
|
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Gets the start color variance of each particle.
|
|
|
|
*
|
|
|
|
* @return The start color variance of each particle.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
const Color4F& getStartColorVar() const { return _startColorVar; }
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Sets the start color variance of each particle.
|
|
|
|
*
|
|
|
|
* @param color The start color variance of each particle.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
void setStartColorVar(const Color4F& color) { _startColorVar = color; }
|
2013-07-23 18:26:26 +08:00
|
|
|
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Gets the end color and end color variation of each particle.
|
|
|
|
*
|
|
|
|
* @return The end color and end color variation of each particle.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
const Color4F& getEndColor() const { return _endColor; }
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Sets the end color and end color variation of each particle.
|
|
|
|
*
|
|
|
|
* @param color The end color and end color variation of each particle.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
void setEndColor(const Color4F& color) { _endColor = color; }
|
2013-07-23 18:26:26 +08:00
|
|
|
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Gets the end color variance of each particle.
|
|
|
|
*
|
|
|
|
* @return The end color variance of each particle.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
const Color4F& getEndColorVar() const { return _endColorVar; }
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Sets the end color variance of each particle.
|
|
|
|
*
|
|
|
|
* @param color The end color variance of each particle.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
void setEndColorVar(const Color4F& color) { _endColorVar = color; }
|
2013-07-23 18:26:26 +08:00
|
|
|
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Gets the start spin of each particle.
|
|
|
|
*
|
|
|
|
* @return The start spin of each particle.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
float getStartSpin() const { return _startSpin; }
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Sets the start spin of each particle.
|
|
|
|
*
|
|
|
|
* @param spin The start spin of each particle.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
void setStartSpin(float spin) { _startSpin = spin; }
|
2013-07-23 18:26:26 +08:00
|
|
|
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Gets the start spin variance of each particle.
|
|
|
|
*
|
|
|
|
* @return The start spin variance of each particle.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
float getStartSpinVar() const { return _startSpinVar; }
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Sets the start spin variance of each particle.
|
|
|
|
*
|
|
|
|
* @param pinVar The start spin variance of each particle.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
void setStartSpinVar(float pinVar) { _startSpinVar = pinVar; }
|
2013-07-23 18:26:26 +08:00
|
|
|
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Gets the end spin of each particle.
|
|
|
|
*
|
|
|
|
* @return The end spin of each particle.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
float getEndSpin() const { return _endSpin; }
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Sets the end spin of each particle.
|
|
|
|
*
|
|
|
|
* @param endSpin The end spin of each particle.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
void setEndSpin(float endSpin) { _endSpin = endSpin; }
|
2013-07-23 18:26:26 +08:00
|
|
|
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Gets the end spin variance of each particle.
|
|
|
|
*
|
|
|
|
* @return The end spin variance of each particle.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
float getEndSpinVar() const { return _endSpinVar; }
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Sets the end spin variance of each particle.
|
|
|
|
*
|
|
|
|
* @param endSpinVar The end spin variance of each particle.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
void setEndSpinVar(float endSpinVar) { _endSpinVar = endSpinVar; }
|
2013-07-23 18:26:26 +08:00
|
|
|
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Gets the emission rate of the particles.
|
|
|
|
*
|
|
|
|
* @return The emission rate of the particles.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
float getEmissionRate() const { return _emissionRate; }
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Sets the emission rate of the particles.
|
|
|
|
*
|
|
|
|
* @param rate The emission rate of the particles.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
void setEmissionRate(float rate) { _emissionRate = rate; }
|
2013-07-23 18:26:26 +08:00
|
|
|
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Gets the maximum particles of the system.
|
|
|
|
*
|
|
|
|
* @return The maximum particles of the system.
|
|
|
|
*/
|
2013-09-08 11:26:38 +08:00
|
|
|
virtual int getTotalParticles() const;
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Sets the maximum particles of the system.
|
|
|
|
*
|
|
|
|
* @param totalParticles The maximum particles of the system.
|
|
|
|
*/
|
2013-09-08 11:26:38 +08:00
|
|
|
virtual void setTotalParticles(int totalParticles);
|
2013-07-23 18:26:26 +08:00
|
|
|
|
|
|
|
/** does the alpha value modify color */
|
2016-09-12 09:44:21 +08:00
|
|
|
void setOpacityModifyRGB(bool opacityModifyRGB) override { _opacityModifyRGB = opacityModifyRGB; }
|
|
|
|
bool isOpacityModifyRGB() const override { return _opacityModifyRGB; }
|
|
|
|
CC_DEPRECATED_ATTRIBUTE bool getOpacityModifyRGB() const { return isOpacityModifyRGB(); }
|
2013-07-23 18:26:26 +08:00
|
|
|
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Gets the particles movement type: Free or Grouped.
|
2013-07-23 18:26:26 +08:00
|
|
|
@since v0.8
|
2015-03-21 18:02:56 +08:00
|
|
|
*
|
|
|
|
* @return The particles movement type.
|
2013-07-23 18:26:26 +08:00
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
PositionType getPositionType() const { return _positionType; }
|
2015-03-21 18:02:56 +08:00
|
|
|
/** Sets the particles movement type: Free or Grouped.
|
|
|
|
@since v0.8
|
|
|
|
*
|
|
|
|
* @param type The particles movement type.
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
void setPositionType(PositionType type) { _positionType = type; }
|
2013-07-23 18:26:26 +08:00
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
// Overrides
|
2014-03-28 14:05:38 +08:00
|
|
|
virtual void onEnter() override;
|
|
|
|
virtual void onExit() override;
|
2013-07-18 07:56:19 +08:00
|
|
|
virtual void update(float dt) override;
|
2013-07-23 18:26:26 +08:00
|
|
|
virtual Texture2D* getTexture() const override;
|
|
|
|
virtual void setTexture(Texture2D *texture) override;
|
2013-09-13 11:41:20 +08:00
|
|
|
/**
|
|
|
|
*@code
|
|
|
|
*When this function bound into js or lua,the parameter will be changed
|
|
|
|
*In js: var setBlendFunc(var src, var dst)
|
|
|
|
*In lua: local setBlendFunc(local src, local dst)
|
|
|
|
*@endcode
|
|
|
|
*/
|
2013-07-23 18:26:26 +08:00
|
|
|
virtual void setBlendFunc(const BlendFunc &blendFunc) override;
|
2013-09-13 11:41:20 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-07-23 18:26:26 +08:00
|
|
|
virtual const BlendFunc &getBlendFunc() const override;
|
2015-11-12 09:49:49 +08:00
|
|
|
|
2016-02-15 23:25:01 +08:00
|
|
|
const std::string& getResourceFile() const { return _plistFile; }
|
2015-11-12 09:49:49 +08:00
|
|
|
|
2016-01-12 17:21:01 +08:00
|
|
|
/// @{
|
|
|
|
/// @name implement Playable Protocol
|
|
|
|
virtual void start() override;
|
|
|
|
virtual void stop() override;
|
2017-01-11 09:31:45 +08:00
|
|
|
/// @} end of PlayableProtocol
|
2016-01-12 17:21:01 +08:00
|
|
|
|
2014-03-21 13:44:29 +08:00
|
|
|
CC_CONSTRUCTOR_ACCESS:
|
2013-11-15 08:21:49 +08:00
|
|
|
/**
|
|
|
|
* @js ctor
|
|
|
|
*/
|
|
|
|
ParticleSystem();
|
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
|
|
|
virtual ~ParticleSystem();
|
|
|
|
|
|
|
|
/** initializes a ParticleSystem*/
|
2015-03-15 02:33:15 +08:00
|
|
|
bool init() override;
|
2013-11-15 08:21:49 +08:00
|
|
|
/** initializes a ParticleSystem from a plist file.
|
|
|
|
This plist files can be created manually or with Particle Designer:
|
|
|
|
http://particledesigner.71squared.com/
|
|
|
|
@since v0.99.3
|
|
|
|
*/
|
|
|
|
bool initWithFile(const std::string& plistFile);
|
2014-03-21 13:44:29 +08:00
|
|
|
|
2013-11-15 08:21:49 +08:00
|
|
|
/** initializes a QuadParticleSystem from a Dictionary.
|
|
|
|
@since v0.99.3
|
|
|
|
*/
|
2013-12-04 17:46:57 +08:00
|
|
|
bool initWithDictionary(ValueMap& dictionary);
|
2014-03-21 13:44:29 +08:00
|
|
|
|
2013-11-15 08:21:49 +08:00
|
|
|
/** initializes a particle system from a NSDictionary and the path from where to load the png
|
|
|
|
@since v2.1
|
|
|
|
*/
|
2013-12-04 17:46:57 +08:00
|
|
|
bool initWithDictionary(ValueMap& dictionary, const std::string& dirname);
|
2014-03-21 13:44:29 +08:00
|
|
|
|
2013-11-15 08:21:49 +08:00
|
|
|
//! Initializes a system with a fixed number of particles
|
|
|
|
virtual bool initWithTotalParticles(int numberOfParticles);
|
2016-06-15 18:31:10 +08:00
|
|
|
|
|
|
|
/** Are the emissions paused
|
|
|
|
@return True if the emissions are paused, else false
|
|
|
|
*/
|
|
|
|
virtual bool isPaused() const;
|
|
|
|
|
|
|
|
/* Pause the emissions*/
|
|
|
|
virtual void pauseEmissions();
|
|
|
|
|
|
|
|
/* UnPause the emissions*/
|
|
|
|
virtual void resumeEmissions();
|
2013-11-15 08:21:49 +08:00
|
|
|
|
2014-03-21 13:44:29 +08:00
|
|
|
protected:
|
2013-07-18 07:56:19 +08:00
|
|
|
virtual void updateBlendFunc();
|
|
|
|
|
|
|
|
/** whether or not the particles are using blend additive.
|
|
|
|
If enabled, the following blending function will be used.
|
|
|
|
@code
|
|
|
|
source blend function = GL_SRC_ALPHA;
|
|
|
|
dest blend function = GL_ONE;
|
|
|
|
@endcode
|
|
|
|
*/
|
|
|
|
bool _isBlendAdditive;
|
|
|
|
|
|
|
|
/** whether or not the node will be auto-removed when it has no particles left.
|
|
|
|
By default it is false.
|
|
|
|
@since v0.8
|
|
|
|
*/
|
|
|
|
bool _isAutoRemoveOnFinish;
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
std::string _plistFile;
|
2012-04-19 14:35:52 +08:00
|
|
|
//! time elapsed since the start of the system (in seconds)
|
2013-06-15 14:03:30 +08:00
|
|
|
float _elapsed;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// Different modes
|
|
|
|
//! Mode A:Gravity + Tangential Accel + Radial Accel
|
|
|
|
struct {
|
|
|
|
/** Gravity value. Only available in 'Gravity' mode. */
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 gravity;
|
2012-04-19 14:35:52 +08:00
|
|
|
/** speed of each particle. Only available in 'Gravity' mode. */
|
|
|
|
float speed;
|
|
|
|
/** speed variance of each particle. Only available in 'Gravity' mode. */
|
|
|
|
float speedVar;
|
|
|
|
/** tangential acceleration of each particle. Only available in 'Gravity' mode. */
|
|
|
|
float tangentialAccel;
|
|
|
|
/** tangential acceleration variance of each particle. Only available in 'Gravity' mode. */
|
|
|
|
float tangentialAccelVar;
|
|
|
|
/** radial acceleration of each particle. Only available in 'Gravity' mode. */
|
|
|
|
float radialAccel;
|
|
|
|
/** radial acceleration variance of each particle. Only available in 'Gravity' mode. */
|
|
|
|
float radialAccelVar;
|
2013-01-21 17:39:48 +08:00
|
|
|
/** set the rotation of each particle to its direction Only available in 'Gravity' mode. */
|
2013-01-22 10:30:22 +08:00
|
|
|
bool rotationIsDir;
|
2012-04-19 14:35:52 +08:00
|
|
|
} modeA;
|
|
|
|
|
|
|
|
//! Mode B: circular movement (gravity, radial accel and tangential accel don't are not used in this mode)
|
|
|
|
struct {
|
|
|
|
/** The starting radius of the particles. Only available in 'Radius' mode. */
|
|
|
|
float startRadius;
|
|
|
|
/** The starting radius variance of the particles. Only available in 'Radius' mode. */
|
|
|
|
float startRadiusVar;
|
|
|
|
/** The ending radius of the particles. Only available in 'Radius' mode. */
|
|
|
|
float endRadius;
|
|
|
|
/** The ending radius variance of the particles. Only available in 'Radius' mode. */
|
2013-07-18 07:56:19 +08:00
|
|
|
float endRadiusVar;
|
2012-09-17 15:02:24 +08:00
|
|
|
/** Number of degrees to rotate a particle around the source pos per second. Only available in 'Radius' mode. */
|
2012-04-19 14:35:52 +08:00
|
|
|
float rotatePerSecond;
|
|
|
|
/** Variance in degrees for rotatePerSecond. Only available in 'Radius' mode. */
|
|
|
|
float rotatePerSecondVar;
|
|
|
|
} modeB;
|
2015-08-31 17:25:34 +08:00
|
|
|
|
|
|
|
//particle data
|
|
|
|
ParticleData _particleData;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-09-24 16:18:51 +08:00
|
|
|
//Emitter name
|
|
|
|
std::string _configName;
|
2013-09-18 16:21:48 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
// color modulate
|
|
|
|
// BOOL colorModulate;
|
|
|
|
|
|
|
|
//! How many particles can be emitted per second
|
2013-06-15 14:03:30 +08:00
|
|
|
float _emitCounter;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// Optimization
|
|
|
|
//CC_UPDATE_PARTICLE_IMP updateParticleImp;
|
|
|
|
//SEL updateParticleSel;
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
/** weak reference to the SpriteBatchNode that renders the Sprite */
|
2013-07-23 18:26:26 +08:00
|
|
|
ParticleBatchNode* _batchNode;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// index of system in batch node array
|
2013-07-23 18:26:26 +08:00
|
|
|
int _atlasIndex;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
//true if scaled or rotated
|
2013-06-15 14:03:30 +08:00
|
|
|
bool _transformSystemDirty;
|
2012-04-19 14:35:52 +08:00
|
|
|
// Number of allocated particles
|
2013-09-08 11:26:38 +08:00
|
|
|
int _allocatedParticles;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
/** Is the emitter active */
|
2013-06-15 14:03:30 +08:00
|
|
|
bool _isActive;
|
2013-07-18 07:56:19 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
/** Quantity of particles that are being simulated at the moment */
|
2013-09-08 11:26:38 +08:00
|
|
|
int _particleCount;
|
2012-09-17 15:02:24 +08:00
|
|
|
/** How many seconds the emitter will run. -1 means 'forever' */
|
2013-07-23 18:26:26 +08:00
|
|
|
float _duration;
|
2012-04-19 14:35:52 +08:00
|
|
|
/** sourcePosition of the emitter */
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 _sourcePosition;
|
2012-04-19 14:35:52 +08:00
|
|
|
/** Position variance of the emitter */
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 _posVar;
|
2012-04-19 14:35:52 +08:00
|
|
|
/** life, and life variation of each particle */
|
2013-07-23 18:26:26 +08:00
|
|
|
float _life;
|
2012-04-19 14:35:52 +08:00
|
|
|
/** life variance of each particle */
|
2013-07-23 18:26:26 +08:00
|
|
|
float _lifeVar;
|
2012-04-19 14:35:52 +08:00
|
|
|
/** angle and angle variation of each particle */
|
2013-07-23 18:26:26 +08:00
|
|
|
float _angle;
|
2012-04-19 14:35:52 +08:00
|
|
|
/** angle variance of each particle */
|
2013-07-23 18:26:26 +08:00
|
|
|
float _angleVar;
|
2010-12-27 17:39:15 +08:00
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
/** Switch between different kind of emitter modes:
|
|
|
|
- kParticleModeGravity: uses gravity, speed, radial and tangential acceleration
|
|
|
|
- kParticleModeRadius: uses radius movement + rotation
|
|
|
|
*/
|
2013-07-26 08:47:42 +08:00
|
|
|
Mode _emitterMode;
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
/** start size in pixels of each particle */
|
2013-07-23 18:26:26 +08:00
|
|
|
float _startSize;
|
2012-04-19 14:35:52 +08:00
|
|
|
/** size variance in pixels of each particle */
|
2013-07-23 18:26:26 +08:00
|
|
|
float _startSizeVar;
|
2012-04-19 14:35:52 +08:00
|
|
|
/** end size in pixels of each particle */
|
2013-07-23 18:26:26 +08:00
|
|
|
float _endSize;
|
2012-04-19 14:35:52 +08:00
|
|
|
/** end size variance in pixels of each particle */
|
2013-07-23 18:26:26 +08:00
|
|
|
float _endSizeVar;
|
2012-04-19 14:35:52 +08:00
|
|
|
/** start color of each particle */
|
2013-07-23 18:26:26 +08:00
|
|
|
Color4F _startColor;
|
2012-04-19 14:35:52 +08:00
|
|
|
/** start color variance of each particle */
|
2013-07-23 18:26:26 +08:00
|
|
|
Color4F _startColorVar;
|
2012-04-19 14:35:52 +08:00
|
|
|
/** end color and end color variation of each particle */
|
2013-07-23 18:26:26 +08:00
|
|
|
Color4F _endColor;
|
2012-04-19 14:35:52 +08:00
|
|
|
/** end color variance of each particle */
|
2013-07-23 18:26:26 +08:00
|
|
|
Color4F _endColorVar;
|
2012-04-19 14:35:52 +08:00
|
|
|
//* initial angle of each particle
|
2013-07-23 18:26:26 +08:00
|
|
|
float _startSpin;
|
2012-04-19 14:35:52 +08:00
|
|
|
//* initial angle of each particle
|
2013-07-23 18:26:26 +08:00
|
|
|
float _startSpinVar;
|
2012-04-19 14:35:52 +08:00
|
|
|
//* initial angle of each particle
|
2013-07-23 18:26:26 +08:00
|
|
|
float _endSpin;
|
2012-04-19 14:35:52 +08:00
|
|
|
//* initial angle of each particle
|
2013-07-23 18:26:26 +08:00
|
|
|
float _endSpinVar;
|
2012-04-19 14:35:52 +08:00
|
|
|
/** emission rate of the particles */
|
2013-07-23 18:26:26 +08:00
|
|
|
float _emissionRate;
|
2012-04-19 14:35:52 +08:00
|
|
|
/** maximum particles of the system */
|
2013-09-08 11:26:38 +08:00
|
|
|
int _totalParticles;
|
2012-04-19 14:35:52 +08:00
|
|
|
/** conforms to CocosNodeTexture protocol */
|
2013-07-23 18:26:26 +08:00
|
|
|
Texture2D* _texture;
|
2012-04-19 14:35:52 +08:00
|
|
|
/** conforms to CocosNodeTexture protocol */
|
2013-07-23 18:26:26 +08:00
|
|
|
BlendFunc _blendFunc;
|
2012-06-14 05:26:28 +08:00
|
|
|
/** does the alpha value modify color */
|
2013-07-23 18:26:26 +08:00
|
|
|
bool _opacityModifyRGB;
|
2013-09-24 16:18:51 +08:00
|
|
|
/** does FlippedY variance of each particle */
|
2013-09-23 10:12:54 +08:00
|
|
|
int _yCoordFlipped;
|
2013-09-18 16:21:48 +08:00
|
|
|
|
2012-06-08 14:11:48 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
/** particles movement type: Free or Grouped
|
2013-07-18 07:56:19 +08:00
|
|
|
@since v0.8
|
2012-11-15 17:16:51 +08:00
|
|
|
*/
|
2013-07-25 14:27:46 +08:00
|
|
|
PositionType _positionType;
|
2016-06-15 18:31:10 +08:00
|
|
|
|
|
|
|
/** is the emitter paused */
|
|
|
|
bool _paused;
|
2013-11-15 08:21:49 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
CC_DISALLOW_COPY_AND_ASSIGN(ParticleSystem);
|
2010-08-23 14:57:37 +08:00
|
|
|
};
|
2011-03-19 10:07:16 +08:00
|
|
|
|
2015-03-24 10:34:41 +08:00
|
|
|
// end of _2d group
|
2012-06-20 18:09:11 +08:00
|
|
|
/// @}
|
|
|
|
|
2012-03-20 15:04:53 +08:00
|
|
|
NS_CC_END
|
2011-03-19 10:07:16 +08:00
|
|
|
|
|
|
|
#endif //__CCPARTICLE_SYSTEM_H__
|