7. cocos2dx Particle System

Source: Internet
Author: User
Www.cocos2dx.net? P66 I. Introduction The particle system refers to using a large number of small genie or some other plotting objects to simulate some fuzzy effects. It is difficult to use the traditional rendering technology. They are often used in chaotic systems, natural phenomena, and chemical reaction animations. Ii. lattice vs rectangle in the previous version of coco

Http://www.cocos2dx.net /? P = 66 I. Introduction The particle system refers to using a large number of small genie or some other plotting objects to simulate some fuzzy effects. It is difficult to use the traditional rendering technology. They are often used in chaotic systems, natural phenomena, and chemical reaction animations. Ii. lattice vs rectangle in the previous version of coco

Http://www.cocos2dx.net /? P = 66

I. Introduction

The particle system refers to a simulation of some fuzzy effects using a large number of small genie or some other drawing objects. It is difficult to use the traditional rendering technology. They are often used in chaotic systems, natural phenomena, and chemical reaction animations.

2. Dot Matrix vs rectangle

In earlier versions of cocos2dx, there are two types of particle systems: rectangular and lattice particle systems:

1) CCParticleSystemQuad

2) CCParticleSystemPoint

CCParticleSystemQuad has some additional features that CCParticleSystemPoint does not support:

1) Rotating Particle System: particles can rotate around the axis, and CCParticleSystemPoint does not have this attribute.

2) particles have sizes. In CCParticleSystemPoint, if the particle size is greater than 64, it will be treated as 64

3) the entire system can be scaled, and the scaling attribute can be used.

Because CCParticleSystemPoint does not support CCParticleBatchNode, it is removed from the cocos2dx particle system ).

Iii. CCParticleBatchNode

A CCParticleBatchNode can reference one texture and only one texture (one image file ). Only CCParticleSystems in the texture can be added to CCSpriteBatchNode. CCParticleSystems added to CCSpriteBatchNode is called in an OpenGL ES plot. If CCParticleSystems is not added to a CCParticleBatchNode, then each particle system needs to be drawn by OpenGL ES once, which is very inefficient.

Create a rectangular Particle System

CCParticleSystemQuad* m_emitter = newCCParticleSystemQuad();m_emitter = CCParticleFire::create();


Iv. Gravity vs radius Mode

Gravity Mode


The gravity mode allows particles to fly or stay away from a central point. This advantage is that it allows a dynamic, organizational effect. You can use the following code to set the gravity mode:

// Gravity mode this-> m_nEmitterMode = kCCParticleModeGravity; this-> modeA. gravity = ccp (0,-90 );


In gravity mode, the following attributes are valid:

Gravity (Point ). The gravity of the particle system.

Speed (float ). The velocity at which particles are emitted.

SpeedVar (float) speed variable

Tangent acceleration of tangencialAccel (float) particles

Variable of the tangent acceleration of tangencialAccelVar (float) particles

Radius acceleration of radialAccel (float) particles.

RadialAccelVar (float) variable of radius acceleration of Particles

Radius Mode


The radius mode allows the particle to rotate in the circle. You can also create a spiral pattern that allows particles to fly out of the screen. You can use the following code to set the radius:

// Radius mode this-> m_nEmitterMode = kCCParticleModeRadius; // set the start radius this-> modeB. startRadius = 0; this-> modeB. startRadiusVar = 0; // ccp (0, 0 );
Radius mode has the following valid attributes:
StartRadius (a float). Start radius of the particle

StartRadiusVar (a float). Start radius variable
EndRadius (a float). Particle end radius
EndRadiusVar (a float). End radius variable
RotatePerSecond (a float). The rotation angle per second around a source point
RotatePerSecondVar (a float). rotation angle variable per second

General Attributes of particles:

StartSize: initial particle size (pixel value)
StartSizeVar
EndSize: The ending size of the particle (if you want the starting size of the particle to be the same as the ending laugh, use kCCParticleStartSizeEqualToEndSize
EndSizeVar
StartColor: particle start color (ccColor4F)
StartColorVar
EndColor: The ending color of the particle.
EndColorVar
StartSpin: used only in CCParticleSystemQuad. The starting degree of Helix
StartSpinVar
EndSpin: used only in CCParticleSystemQuad to end the helix.
EndSpinVar
Life particle life time, in seconds
LifeVar
Angle: particle start angle, float
AngleVar
Positon: CCPoint particle position
PositonVar
CenterOfGravity: CGPoint

Common system attributes:

EmissionRate duration (a float): number of particles emitted per second

Duration (a float): Particle System survival time

BlendFunc (a ccBlendFunc): the OpenGL rendering function used for system rendering.

PositionType (a tCCPositionType).: Use the kCCPositionTypeFree (default) attribute to move particles freely. Or use kCCPositionTypeGrouped to move the particles in a group.

Texture (a CCTexture2D). Particle texture

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.