Permalink
Browse files

Particle System duplication

- CCParticleSystemQuad can be duplicated for optimization purposes.
  • Loading branch information...
1 parent ad15efe commit 8255e2962d339c003b561cc40d9348a5f94f4ba2 Brandon Dorris committed Apr 27, 2012
@@ -345,6 +345,8 @@ class CC_DLL CCParticleSystem : public CCNode, public CCTextureProtocol
@since v0.99.3
*/
static CCParticleSystem * particleWithFile(const char *plistFile);
+
+ bool duplicate(CCParticleSystem &system);
/** initializes a CCParticleSystem from a plist file.
This plist files can be creted manually or with Particle Designer:
@@ -66,6 +66,8 @@ class CC_DLL CCParticleSystemQuad : public CCParticleSystem
This plist files can be creted manually or with Particle Designer:
*/
static CCParticleSystemQuad * particleWithFile(const char *plistFile);
+
+ CCParticleSystemQuad * duplicate();
/** initialices the indices for the vertices*/
void initIndices();
@@ -326,6 +326,79 @@ bool CCParticleSystem::initWithDictionary(CCDictionary<std::string, CCObject*> *
CC_SAFE_DELETE(image);
return bRet;
}
+
+bool CCParticleSystem::duplicate(CCParticleSystem &system)
+{
+ bool bRet = false;
+ do
+ {
+ if(system.initWithTotalParticles(m_uTotalParticles))
+ {
+ // angle
+ system.setAngle(m_fAngle);
+ system.setAngleVar(m_fAngleVar);
+
+ // duration
+ system.setDuration(m_fDuration);
+
+ // blend function
+ system.setBlendFunc(m_tBlendFunc);
+
+ // color
+ system.setStartColor(m_tStartColor);
+ system.setStartColorVar(m_tStartColorVar);
+
+ system.setEndColor(m_tEndColor);
+ system.setEndColorVar(m_tEndColorVar);
+
+ // particle size
+ system.setStartSize(m_fStartSize);
+ system.setStartSizeVar(m_fStartSizeVar);
+ system.setEndSize(m_fEndSize);
+ system.setEndSizeVar(m_fEndSizeVar);
+
+ // position
+ system.setPosition(this->getPosition());
+ system.setPosVar(m_tPosVar);
+
+ // Spinning
+ system.setStartSpin(m_fStartSpin);
+ system.setStartSpinVar(m_fStartSpinVar);
+ system.setEndSpin(m_fEndSpin);
+ system.setEndSpinVar(m_fEndSpinVar);
+
+ system.setEmitterMode(m_nEmitterMode);
+
+ // Mode A: Gravity + tangential accel + radial accel
+ if( m_nEmitterMode == kCCParticleModeGravity ) {
+ system.modeA = modeA;
+ } else if( m_nEmitterMode == kCCParticleModeRadius ) {
+ system.modeB = modeB;
+ } else {
+ CCAssert( false, "Invalid emitterType in config file");
+ CC_BREAK_IF(true);
+ }
+
+ // life span
+ system.setLife(m_fLife);
+ system.setLifeVar(m_fLifeVar);
+
+ // emission Rate
+ system.setEmissionRate(m_fEmissionRate);
+
+ // texture
+ system.setTexture(m_pTexture);
+ CCAssert( system.m_pTexture != NULL, "CCParticleSystem: error loading the texture");
+
+ CC_BREAK_IF(!system.m_pTexture);
+ system.m_pTexture->retain();
+ bRet = true;
+ }
+ } while (0);
+
+ return bRet;
+}
+
bool CCParticleSystem::initWithTotalParticles(unsigned int numberOfParticles)
{
m_uTotalParticles = numberOfParticles;
@@ -335,5 +335,16 @@ void CCParticleSystemQuad::draw()
// restore GL default state
// -
}
+
+CCParticleSystemQuad* CCParticleSystemQuad::duplicate()
+{
+ CCParticleSystemQuad *system = new CCParticleSystemQuad();
+ system->autorelease();
+ if (CCParticleSystem::duplicate(*system)) {
+
+ }
+
+ return system;
+}
}// namespace cocos2d

0 comments on commit 8255e29

Please sign in to comment.