My English is very poor.
sorry about that…
I have some problem with cocos2d-x particle
plz check added project.
I want to use particle in real-time.
for example, in update(ccTime dt) method…
void HelloWorld::update(ccTime dt)
{
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
// TEST 1 : Explosion effect every 1 second
// it make by static function particleWithFile
// and setIsAutoRemoveOnFinish(true)
// so I think I don't need to release()
// but It makes memory increase every time
static ccTime tExplosionTime = 0.f;
tExplosionTime += dt;
if(tExplosionTime >= 1.f)
{
tExplosionTime -= 1.f;
CCParticleSystem *pExplosion = CCParticleSystemQuad::particleWithFile("ExplodingRing.plist");
pExplosion->setPosition(ccp(winSize.width/2, winSize.height/2));
this->addChild(pExplosion, 10);
pExplosion->setIsAutoRemoveOnFinish(true);
}
// TEST 2 : Sun effect every 0.3 second
// It moves from (0, 0) to (200, 200) in 1 second
// every particle saved by vector
// and check every frame that particles reach to (200, 200)
// and removeChild(particle, true);
// but It make memory increase every time too.
static ccTime tSunTime = 0.f;
tSunTime += dt;
if(tSunTime >= 0.3f)
{
tSunTime -= 0.3f;
CCParticleSystem *pParticleSun = CCParticleSun::node();
pParticleSun->setTexture(CCTextureCache::sharedTextureCache()->addImage("fire.png"));
pParticleSun->setScale(0.2f);
pParticleSun->setSpeed(5.f);
pParticleSun->setLife(0.2f);
pParticleSun->setPosition(ccp(0, 0));
this->addChild(pParticleSun, 10);
// bezierTo
ccBezierConfig bezier;
bezier.controlPoint_1 = ccp(50, 50);
bezier.controlPoint_2 = ccp(100, 100);
bezier.endPosition = ccp(200, 200);
CCActionInterval* bezierTo = cocos2d::CCBezierTo::actionWithDuration(1.f, bezier);
pParticleSun->runAction(bezierTo);
vSuns.push_back(pParticleSun);
}
for(vector::iterator iter = vSuns.begin(); iter != vSuns.end(); iter++)
{
CCParticleSystem* pCurSun = (CCParticleSystem*)*iter;
CCPoint pt = pCurSun->getPosition();
if(pt.x == 200 && pt.y == 200)
{
this->removeChild(pCurSun, true);
iter = vSuns.erase(iter);
if(iter == vSuns.end())
break;
}
}
}
How can I fix them?
I really want to know.
ParticleTest.zip (174.2 KB)