继承图:
两个类都继承自Node(v2.x中的CCNode,PS:官网又弄反了)和TextureProtocol(v2.x中的CCTextureProtocol)。
(注意:后面将全部用V3.0的概念,即不会再加入类名的CC前缀)
ParticleBatchNode类似于一个批处理节点,它将通过一次调用OpenGL来绘制它的子节点(通常称之为“batch draw(咋翻译啊这里)”)。
一个ParticleBatchNode实例可以引用一个且只能引用一个texture(一个图片文件或者一个地图结构)。只有被包含在texture的ParticleSystems才可以被添加到ParticleBatchNode。
所有添加到一个ParticleBatchNode的ParticleSystems绘制只通过一次调用OpenGL ES。
注意:如果ParticleSystems没被添加到ParticleBatchNode,那么每一个ParticleSystem的绘制都得调用一次OpenGLES,而且它很没效率。
const BlendFunc BlendFunc::ALPHA_NON_PREMULTIPLIED = {GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA};
同时也用BlendFunc::ALPHA_PREMULTIPLIED来取代CC_BLEND_SRC和CC_BLEND_DST。emitter.radialAccel = 15;
emitter.startSpin = 0;
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 |
kCCPositionTypeFree /kPositionTypeFree |
ParticleSystem::PositionType::FREE |
kCCPositionTypeRelative /kPositionTypeRelative |
ParticleSystem::PositionType::RELATIVE |
kCCPositionTypegRrouped /kPositionTypegRrouped |
ParticleSystem::PositionType::GROUPED |
kCCParticleDurationInfinity /kParticleDurationInfinity |
ParticleSystem::DURATION_INFINITY |
kCCParticleStartSizeEqualToEndSize /kParticleStartSizeEqualToEndSize |
ParticleSystem::START_SIZE_EQUAL_TO_END_SIZE |
kCCParticleStartRadiusEqualToEndRadius /kParticleStartRadiusEqualToEndRadius |
ParticleSystem::START_RADIUS_EQUAL_TO_END_RADIUS |
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; }; |
/* // Cocos2d-x-2.x CCSize size = CCDirector::sharedDirector()->getWinSize(); ParticleSystemQuad* m_emitter = ParticleSystemQuad::createWithTotalParticles(900); m_emitter->setTexture(CCTextureCache::sharedTextureCache()->addImage("fire.png")); */ // Cocos2d-x-3.x auto size = Director::getInstance()->getWinSize(); auto m_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.x m_emitter->setDuration(-1); m_emitter->setGravity(Point(0, -240)); // in Cocos2d-x-2.x CCPoint(0, -240) is used m_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(30); m_emitter->setStartSizeVar(0); m_emitter->setEndSize(20.0f); m_emitter->setEndSizeVar(0); m_emitter->setEmissionRate(100); addChild(m_emitter,10);