Renaissance
Renaissance

Reputation: 554

Particle system not getting visible for first time in cocos2d-x

I am working in cocos2d-x for last two weeks.I have made one game in cocos2d-iphone. Now i am trying to make the same that from android devices using cocos2d-x. I am using particle system when player will collect the stars. When player is collecting a star for the first time, the particle system is not getting display. After that for every star collection it gets visible. I have check that it is executing the function which is used for displaying particle system.

Code for adding particle system is:

CCParticleSystemQuad *system = CCParticleSystemQuad::create("stars.plist");
                            system->setTexture(CCTextureCache::sharedTextureCache()->addImage("stern.png"));
                            system->setPosition(starSprite->getPosition().x, starSprite->getPosition().y);
system->setLife(2);
system->setLifeVar(2);
system->setAutoRemoveOnFinish(true);
this->addChild(system,2);

Does anyone tell me why this is happening?

Upvotes: 0

Views: 1185

Answers (1)

bbm20891
bbm20891

Reputation: 144

Use this code once to define your particlesystem, declare "system" in h file so you can use it later in cpp file.

CCParticleSystemQuad *system = CCParticleSystemQuad::create("stars.plist");
                            system->setTexture(CCTextureCache::sharedTextureCache()->addImage("stern.png"));
                            system->setPosition(starSprite->getPosition().x, starSprite->getPosition().y);
system->setLife(2);
system->setLifeVar(2);
system->stopSystem();
this->addChild(system,2);

now when u collect star just put this line

system->resetSystem();

each time you collect star the particle system will be reset and displayed :)

Upvotes: 1

Related Questions