4) Cocos2d-x Particle System

Source: Internet
Author: User

4) Cocos2d-x Particle System

CCparticleSystem class encapsulation controls and schedules particles. The operations include:

1. generate particles

2. Update particle status

3. Reclaim invalid Particles

CCparticleSystem derives CCParticleSystemPoint (gravity Particle System) and CCParticleSystemQuad (radioactive particle system)

Particle effects:

CCParticleExplosion (explosive particle effect) CCParticleFireworks (Fireworks particle effect) CCParticleFire (flame particle effect) CCParticleFlower (bouquet particle effect) CCParticleGalaxy (Galaxy particle effect) CCParticleMeteor (meteor particle effect) CCParticleSpiral (vortex particle effect) CCParticleSnow (snow particle effect) CCParticleSmoke (smoke particle effect) CCParticleSun (Sun particle effect) CCParticleRain (rain particle effect)

Instance:

1. Create a particle effect by creating a texture image

CCParticleSystem *particle = CCParticleExplosion::create();particle->setTexture(CCTextureCache::sharedTextureCache()->addImage("fire.png"));particle->setAutoRemoveOnFinish(true);this->addChild(particle);

2. Create a radioactive particle system (gravity-free) CCParticleSystemQuad Based on the attributes

CCParticleSystem * m_emitter; m_emitter = new CCParticleSystemQuad (); m_emitter-> initwithtotalparticipant (300); // set the texture m_emitter-> setTexture (CCTextureCache: sharedTextureCache () -> addImage ("fire.png"); m_emitter-> setDuration (-1); // alignment m_emitter-> setGravity (CCPointZero ); // angle m_emitter-> setAngle (90); m_emitter-> setAngleVar (360); // speed m_emitter-> setSpeed (160); m_emitter-> setSpeedVar (20 ); // Life Cycle m_emitter-> setLife (4); m_emitter-> setLifeVar (1); // particle rotation m_emitter-> setStartSpin (0); m_emitter-> setStartSizeVar (0 ); m_emitter-> setEndSpin (0); m_emitter-> setEndSpinVar (0); // The Particle color ccColor4F startColor = {0.5f, 0.5f, 0.5f, 0.5f }; m_emitter-> setStartColor (startColor); ccColor4F startColor2 = {0.5f, 0.5f, 0.5f, 1.0f}; m_emitter-> setStartColorVar (startColor2); ccColor4F startColor3 = {0.1f, 0.1f, 0.1f, 0.2f}; m_emitter-> setEndColor (startColor3); ccColor4F startColor4 = {0.1f, 0.1f, 0.1f, 0.2f}; m_emitter-> setEndColorVar (startColor4 ); // particle size m_emitter-> setStartSize (20366f); m_emitter-> setStartSizeVar (10.0f); m_emitter-> setEndSize (32.0f); m_emitter-> setEndSizeVar (8.0f ); // number of particles per second m_emitter-> setEmissionRate (m_emitter-> gettotalparticipant ()/m_emitter-> getLife (); // number of particles generated per second = Total number of particles/survival time; // position m_emitter-> setPosition (ccp (visibleSize. width/2, visibleSize. height/2); this-> addChild (m_emitter );
Effect:



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.