Can Someone Give Me A Simple COcos2d-X Particle Example?

10.8k views Asked by At

I just want to make a CCParticleExplsion using Cocos2d-x and C++, but can't seem to find it after searching all over. ObjC example:

CCParticleSystem *firework = [[CCParticleExplosion alloc] initWithTotalParticles:200];
[self addChild:firework];
[firework setTexture:[[CCTextureCache sharedTextureCache] addImage:@"star.png"]];
3

There are 3 answers

0
m.ding On BEST ANSWER

In most cases, the ParticleTexture comes with the plist file, and the whole plist file is from the particle designer. Usually, we use

CCParticleSystemQuad* p = CCParticleSystemQuad::create("whatever_particle.plist");
this->addChild(p);

but if you wanna use the particles comes with cocos2d-x, you can check how to use them in the Test Cases that comes with the cocos2d-x framework. the file name is ParticleTest.cpp

0
srikanth chitturi On

see the tests folder in the cocos2d-x root folder.

0
Nathanael Weiss On

CCParticleExplosion is declared in cocos2dx/particle_nodes/CCParticleExamples.h.

Here's the C++ equivalent of your Objective C code:

CCTexture2D* texture = CCTextureCache::sharedTextureCache()->textureForKey("star.png");
CCParticleExplosion* firework = CCParticleExplosion::create();
firework->setTexture(texture);