Making Cocos2d-X snowflake effect

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

Methods 1 first defines an Snowflake effect
Snowflake.h
static void createParticleSnowRing(cocos2d::CCPoint position, Engine::String image ,int radia, CCNode* parentNode);
Snowflake.cpp
void ParticleEffects::createParticleSnowRing(cocos2d::CCPoint position, Engine::String image ,int radia, CCNode* parentNode) {
CCParticleSnow * particle = CCParticleSnow::node();
//The custom of snow
particle->setTexture(CCTextureCache::sharedTextureCache()->addImage(image.c_str()));
//The total number of particles
particle->setTotalParticles(400);
//Snow seconds
particle->setDuration(30);
//The snow began to size
particle->setStartSize(10);
//The snowflakes size floating
particle->setStartSizeVar(5);
//Snow end size
particle->setEndSize(5);
particle->setEndSizeVar(0);
//Initial velocity
particle->setSpeed(200);
particle->setSpeedVar(100);
//The descending speed of Y negative x negative westward blowing
particle->setGravity(ccp(-20,-70));
//Each snowflake life time
particle->setLife(20.0f);
particle->setLifeVar(2.0f);
// particle->setPosition(ccp(240, 320));
//The release of snow velocity particle.emissionRate = particle.totalParticles/particle.life;
particle->setEmissionRate(100);
CCSize a = CCDirector::sharedDirector()->getWinSize();
//Animation is completed automatically removed from the upper layer particles
particle->setAutoRemoveOnFinish(true);
//The release of the particle position if you want to set the position at the time of the call, you can look at the following code
parentNode->addChild(particle,3);
}
Write down what you want to call 2 in local code:
Engine::String image =Engine::StringUtil::format("Snowflake%d.png",arc4random()%7 + 1 );
CCSizes =CCDirector::sharedDirector()->getWinSize();
int x = s.width;
int y = s.height;
CCPoint position = ccp(arc4random() % x,arc4random() % y);
this-> createExplodingRing(position, image,arc4random()%30+50,this);
3 if you write a separate class of words, so call
EffectsScene=newParticleEffects();
EffectsScene-> createExplodingRing(position, image, arc4random()%30+50,this);
4 the direct use of the

CCParticleSnow* particle =CCParticleSnow::node();
particle->setTexture(CCTextureCache::sharedTextureCache()->addImage("snowflakes.png"));
particle->setTotalParticles(400);
particle->setDuration(30);
particle->setStartSize(10);
particle->setStartSizeVar(5);
particle->setEndSize(5);
particle->setEndSizeVar(0);
particle->setSpeed(200);
particle->setSpeedVar(100);
particle->setGravity(ccp(-20,-70));
particle->setLife(20.0f);
particle->setLifeVar(2.0f);
particle->setEmissionRate(100);
CCSizea =CCDirector::sharedDirector()->getWinSize();
particle->setAutoRemoveOnFinish(true);
particle->setPosition(CCPoint(a.width/2,a.height+10));
particle->setPosVar(ccp(a.width/2+50,0));
this->addChild(particle,20);

5 some effect:
-- CCParticleExplosion (explosive particle effects)
-- CCParticleFireworks (fireworks particle effects)
-- CCParticleFire (flame particle effects)
-- CCParticleFlower (bouquet particle effects)
-- CCParticleGalaxy (Galaxy particle effects)
-- CCParticleMeteor (meteor particles)
-- CCParticleSpiral (vortex particle effects)
-- CCParticleSnow (snow particle effects)
-- CCParticleSmoke (smoke particle effects)
-- CCParticleSun (solar particle effect)
-- CCParticleRain (rain particle effects)

Results show that diagram as follows:

The snowflake effect


Solar particle effect

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Helena at December 28, 2013 - 12:09 PM