Cocos2d Particle System II

Source: Internet
Author: User

Properties of the particle system:
    • The speed at which particles are emitted
    • Gravity mode (Mode a):
      • Gravity
      • Direction
      • Speed +-Change
      • Tangential acceleration +-change
      • Radial Acceleration +-change
    • Radius mode (mode B):
      • Start radius +-Change
      • End RADIUS +-Change
      • Rotate +-Change
    • Common Properties for all modes:
      • Life
      • Start rotation
      • End rotation
      • Start size
      • End Dimension
      • Start color
      • End Color
      • Life
      • Synthetic functions
      • Texture
COCOS2D supports particles generated by particle designer ( "radius mode" in particle The designer uses a fixed 30hz frequency, but the frequency is variable in the cocos2d, but the results remain consistent. COCOS2D supports all the variables in particle designer, and a little bit more:
    • Particle rotation (for particlesystemquad)
    • Tangent acceleration (gravity mode)
    • Radial Acceleration (Gravity mode)
    • Radius direction (RADIUS mode) (particle designer only supports outward and inward orientation)
All of the above properties are mutable at run time, such as: [CPP]View Plaincopy
    1. Emitter.radialaccel = 15;
    2. Emitter.startspin = 0;
Different places:
cocos2d-x-2.x cocos2d-x-3.x
kCCParticleDefaultCapacity kParticleDefaultCapacity
ParticleSystem::Mode kCCParticleModeGravity ParticleSystem::Mode::GRAVITY
ParticleSystem::Mode kCCParticleModeRadius ParticleSystem::Mode::RADIUS
N/A typedef ParticleSystem::PositionType tPositionType
    • More than 20 inline functions are defined in the header file to replace macros like Cc_property (VarType, VarName, Funname) and Cc_property_readonly (VarType, VarName, Funname)
cocos2d-x-2.x cocos2d-x-3.x
CC_PROPERTY(int, m_nEmitterMode, EmitterMode) Mode _emitterMode;inline Mode getEmitterMode() const { return _emitterMode; };inline void setEmitterMode(Mode mode) { _emitterMode = mode; };
CC_PROPERTY(CCParticleBatchNode*, m_pBatchNode, BatchNode) ParticleBatchNode* _batchNode;virtual ParticleBatchNode* getBatchNode() const;virtual void setBatchNode(ParticleBatchNode* batchNode);
CC_PROPERTY_READONLY(unsigned int, m_uParticleCount, ParticleCount) int _particleCount;inline unsigned int getParticleCount() const { return _particleCount; };
CC_PROPERTY(float, m_fDuration, Duration) float _duration;inline float getDuration() const { return _duration; };inline void setDuration(float duration) { _duration = duration; };
CC_PROPERTY_PASS_BY_REF(CCPoint, m_tSourcePosition, SourcePosition) Point _sourcePosition;inline const Point& getSourcePosition() const { return _sourcePosition; };inline void setSourcePosition(const Point& pos) { _sourcePosition = pos; };
CC_PROPERTY_PASS_BY_REF(CCPoint, m_tPosVar, PosVar) Point _posVar;inline const Point& getPosVar() const { return _posVar; };inline void setPosVar(const Point& pos) { _posVar = pos; };
CC_PROPERTY(float, m_fLife, Life) float _life;inline float getLife() const { return _life; };inline void setLife(float life) { _life = life; };
CC_PROPERTY(float, m_fLifeVar, LifeVar) float _lifeVar;inline float getLifeVar() const { return _lifeVar; };inline void setLifeVar(float lifeVar) { _lifeVar = lifeVar; };
CC_PROPERTY(float, m_fAngle, Angle) float _angle;inline float getAngle() const { return _angle; };inline void setAngle(float angle) { _angle = angle; };
CC_PROPERTY(float, m_fAngleVar, AngleVar) float _angleVar;inline float getAngleVar() const { return _angleVar; };inline void setAngleVar(float angleVar) { _angleVar = angleVar; };
CC_PROPERTY(float, m_fStartSize, StartSize) float _startSize;inline float getStartSize() const { return _startSize; };inline void setStartSize(float startSize) { _startSize = startSize; };
CC_PROPERTY(float, m_fStartSizeVar, StartSizeVar) float _startSizeVar;inline float getStartSizeVar() const { return _startSizeVar; };inline void setStartSizeVar(float sizeVar) { _startSizeVar = sizeVar; };
CC_PROPERTY(float, m_fEndSize, EndSize) float _endSize;inline float getEndSize() const { return _endSize; };inline void setEndSize(float endSize) { _endSize = endSize; };
CC_PROPERTY(float, m_fEndSizeVar, EndSizeVar) float _endSizeVar;inline float getEndSizeVar() const { return _endSizeVar; };inline void setEndSizeVar(float sizeVar) { _endSizeVar = sizeVar; };
CC_PROPERTY_PASS_BY_REF(ccColor4F, m_tStartColor, StartColor) Color4F _startColor;inline const Color4F& getStartColor() const { return _startColor; };inline void setStartColor(const Color4F& color) { _startColor = color; };
CC_PROPERTY_PASS_BY_REF(ccColor4F, m_tStartColorVar, StartColorVar) Color4F _startColorVar;inline const Color4F& getStartColorVar() const { return _startColorVar; };inline void setStartColorVar(const Color4F& color) { _startColorVar = color; };
CC_PROPERTY_PASS_BY_REF(ccColor4F, m_tEndColorVar, EndColorVar) Color4F _endColorVar;inline const Color4F& getEndColor() const { return _endColor; };inline void setEndColor(const Color4F& color) { _endColor = color; };
CC_PROPERTY(float, m_fStartSpin, StartSpin) float _startSpin;inline float getStartSpin() const { return _startSpin; };inline void setStartSpin(float spin) { _startSpin = spin; };
CC_PROPERTY(float, m_fStartSpinVar, StartSpinVar) float _startSpinVar;inline float getStartSpinVar() const { return _startSpinVar; };inline void setStartSpinVar(float pinVar) { _startSpinVar = pinVar; };
CC_PROPERTY(float, m_fEndSpin, EndSpin) float _endSpinVar;inline float getEndSpin() const { return _endSpin; };inline void setEndSpin(float endSpin) { _endSpin = endSpin; };
CC_PROPERTY(float, m_fEndSpinVar, EndSpinVar) float _endSpinVar;inline float getEndSpinVar() const { return _endSpinVar; };inline void setEndSpinVar(float endSpinVar) { _endSpinVar = endSpinVar; };
CC_PROPERTY(float, m_fEmissionRate, EmissionRate) float _emissionRate;inline float getEmissionRate() const { return _emissionRate; };inline void setEmissionRate(float rate) { _emissionRate = rate; };
CC_PROPERTY(unsigned int, m_uTotalParticles, TotalParticles) int _totalParticles;virtual int getTotalParticles() const;virtual void setTotalParticles(int totalParticles);
CC_PROPERTY(CCTexture2D*, m_pTexture, Texture) Texture2D* _texture;virtual Texture2D* getTexture() const override;virtual void setTexture(Texture2D *texture) override;
CC_PROPERTY(ccBlendFunc, m_tBlendFunc, BlendFunc) BlendFunc _blendFunc;virtual void setBlendFunc(const BlendFunc &blendFunc) override;virtual const BlendFunc &getBlendFunc() const override;
CC_PROPERTY(bool, m_bOpacityModifyRGB, OpacityModifyRGB) bool _opacityModifyRGB;inline void setOpacityModifyRGB(bool opacityModifyRGB) { _opacityModifyRGB = opacityModifyRGB; };inline bool isOpacityModifyRGB() const { return _opacityModifyRGB; };CC_DEPRECATED_ATTRIBUTE inline bool getOpacityModifyRGB() const { return isOpacityModifyRGB(); }
CC_PROPERTY(tCCPositionType, m_ePositionType, PositionType) PositionType _positionType;inline PositionType getPositionType() const { return _positionType; };inline void setPositionType(PositionType type) { _positionType = type; };
CC_SYNTHESIZE(unsigned int, m_uAtlasIndex, AtlasIndex) int _atlasIndex;inline int getAtlasIndex() const { return _atlasIndex; };inline void setAtlasIndex(int index) { _atlasIndex = index; };
    • Added two properties in 3.x std::string _configname; and int _ycoordflipped;
Ccparticlesystemquad and Particlesystemquad are similar: Inheritance Diagram Particlesystemquad is a subclass of Particlesystem. It contains all the features in the Particlesystem. Here are some of its unique features and limitations:
    • The particle size can be any float value;
    • The system can be scaled;
    • particles can be rotated;
    • Support Subrects (do not know how to translate, "sub-moment" did not understand their own)
    • Support for batch rendering starting from version 1.1
Different places: 3.x does not change, like in 2.x using 3.x class can be, more details click here for example:
    • Here is an example of Particlesystem:
/*cocos2d-x-2.xCcsize size = Ccdirector::shareddirector ()->getwinsize ();particlesystemquad* M_emitter = particlesystemquad::createwithtotalparticles (900);M_emitter->settexture (Cctexturecache::sharedtexturecache ()->addimage ("Fire.png"));*/cocos2d-x-3.xAutoSize=Director::GetInstance()-Getwinsize();AutoM_emitter=Particlesystemquad::Createwithtotalparticles(900);M_emitter-SetTexture(Director::GetInstance()-Gettexturecache()-AddImage("Fire.png"));The code below we can use both in 2.x and 3.xM_emitter-Setduration(-1);M_emitter-Setgravity(Point(0,-240));In cocos2d-x-2.x ccpoint (0, -240) is usedM_emitter-Setangle(90);M_emitter-Setanglevar(360);M_emitter-Setradialaccel(50);M_emitter-Setradialaccelvar(0);M_emitter-Settangentialaccel(30);M_emitter-Settangentialaccelvar(0);M_emitter-SetPosition(Point(Size.Width/2,Size.Height));M_emitter-Setposvar(Point(400,0));M_emitter-Setlife(4);M_emitter-Setlifevar(2);M_emitter-Setstartspin(30);M_emitter-Setstartspinvar(60);M_emitter-Setendspin(60);M_emitter-Setendspinvar(60);M_emitter-Setstartcolor(color4f(255,255,255,1));M_emitter-Setstartcolorvar(color4f(0,0,0,0));M_emitter-Setendcolor(color4f(255,255,255,1));M_emitter-Setendcolorvar(color4f(0,0,0,0));M_emitter->setstartsize (30m_emitter->setstartsizevar ( 0m_emitter->setendsize ( 20.0f); m_emitter->setendsizevar (0 ); m_emitter->setemissionrate ( 100addchild (m_emitter,10                
    • You can also use the following sub-classes of cow B to easily create some commonly used particle effects
      • Particleexplosion, Particlefire, Particlefireworks, Particleflower, Particlegalaxy, Particlemeteor, ParticleRain, Particlesmoke, Particlesnow, Particlespiral, Particlesun

Cocos2d Particle System II

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: 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.