From 5c915fc584bcb6297a0e8d02d3551b0e471bab75 Mon Sep 17 00:00:00 2001 From: PickleMan Date: Mon, 21 Jan 2013 04:39:48 -0500 Subject: [PATCH] Added rotationIsDir to Particle System. It sets the rotation of each particle to its direction --- cocos2dx/particle_nodes/CCParticleSystem.cpp | 19 +++++++++++++++++++ cocos2dx/particle_nodes/CCParticleSystem.h | 6 +++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/cocos2dx/particle_nodes/CCParticleSystem.cpp b/cocos2dx/particle_nodes/CCParticleSystem.cpp index 26ba67f3a2..ae423a3b31 100644 --- a/cocos2dx/particle_nodes/CCParticleSystem.cpp +++ b/cocos2dx/particle_nodes/CCParticleSystem.cpp @@ -124,6 +124,7 @@ CCParticleSystem::CCParticleSystem() modeA.tangentialAccelVar = 0; modeA.radialAccel = 0; modeA.radialAccelVar = 0; + modeA.rotationIsDir = false; modeB.startRadius = 0; modeB.startRadiusVar = 0; modeB.endRadius = 0; @@ -277,6 +278,9 @@ bool CCParticleSystem::initWithDictionary(CCDictionary *dictionary, const char * // tangential acceleration modeA.tangentialAccel = dictionary->valueForKey("tangentialAcceleration")->floatValue(); modeA.tangentialAccelVar = dictionary->valueForKey("tangentialAccelVariance")->floatValue(); + + // rotation is dir + modeA.rotationIsDir = dictionary->valueForKey("rotationIsDir")->boolValue(); } // or Mode B: radius movement @@ -544,6 +548,9 @@ void CCParticleSystem::initParticle(tCCParticle* particle) // tangential accel particle->modeA.tangentialAccel = modeA.tangentialAccel + modeA.tangentialAccelVar * CCRANDOM_MINUS1_1(); + // rotation is dir + if(modeA.rotationIsDir) + particle->rotation = -CC_RADIANS_TO_DEGREES(ccpToAngle(particle->modeA.dir)); } // Mode Radius: B @@ -897,6 +904,18 @@ float CCParticleSystem::getRadialAccelVar() return modeA.radialAccelVar; } +void CCParticleSystem::setRotationIsDir(bool t) +{ + CCAssert( m_nEmitterMode == kCCParticleModeGravity, "Particle Mode should be Gravity"); + modeA.rotationIsDir = t; +} + +bool CCParticleSystem::getRotationIsDir() +{ + CCAssert( m_nEmitterMode == kCCParticleModeGravity, "Particle Mode should be Gravity"); + return modeA.rotationIsDir; +} + void CCParticleSystem::setGravity(const CCPoint& g) { CCAssert( m_nEmitterMode == kCCParticleModeGravity, "Particle Mode should be Gravity"); diff --git a/cocos2dx/particle_nodes/CCParticleSystem.h b/cocos2dx/particle_nodes/CCParticleSystem.h index e60aba4caf..7b1566b33d 100644 --- a/cocos2dx/particle_nodes/CCParticleSystem.h +++ b/cocos2dx/particle_nodes/CCParticleSystem.h @@ -196,6 +196,8 @@ protected: float radialAccel; /** radial acceleration variance of each particle. Only available in 'Gravity' mode. */ float radialAccelVar; + /** set the rotation of each particle to its direction Only available in 'Gravity' mode. */ + bool rotationIsDir } modeA; //! Mode B: circular movement (gravity, radial accel and tangential accel don't are not used in this mode) @@ -277,6 +279,8 @@ public: virtual void setRadialAccel(float t); virtual float getRadialAccelVar(); virtual void setRadialAccelVar(float t); + virtual bool getRotationIsDir(); + virtual void setRotationIsDir(bool t); // mode B virtual float getStartRadius(); virtual void setStartRadius(float startRadius); @@ -375,7 +379,7 @@ public: */ static CCParticleSystem * create(const char *plistFile); - //! create a system with a fixed number of particles + //! create a system with a fixed number of particles static CCParticleSystem* createWithTotalParticles(unsigned int numberOfParticles); /** initializes a CCParticleSystem*/