本文来自http://blog.csdn.net/runaying ,引用必须注明出处!
cocos2d-x节点(CCParticleBatchNode.h)API
温馨提醒:为了大家能更好学习,强烈推荐大家看看本人的这篇博客 Cocos2d-X权威指南笔记
批量绘制粒子
///cocos2d-x-3.0alpha0/cocos2dx/particle_nodes
//批量绘制粒子
#ifndef __CCPARTICLEBATCHNODE_H__
#define __CCPARTICLEBATCHNODE_H__
#include "base_nodes/CCNode.h"
#include "CCProtocols.h"
NS_CC_BEGIN
class Texture2D;
class TextureAtlas;
class ParticleSystem;
/**
* @addtogroup particle_nodes(粒子节点)
* @{
*/
#define kParticleDefaultCapacity 500
/** ParticleBatchNode 和批处理节点一样: 如果它包含 children, 它会在1 次 OpenGL 调用里面绘制它们
* (often known as "batch draw").
*
* ParticleBatchNode 可以引用一个只有 texture 的对象 (one image file, one texture atlas).
* 只有 ParticleSystems 包含 texture 的时候它才可以被添加到 SpriteBatchNode.
* 所有添加到 SpriteBatchNode 里面的 ParticleSystems 都会在同一 OpenGL ES 调用里面被绘制.
* 如果 ParticleSystems 没有被添加到 ParticleBatchNode 那么每一个 ParticleSystems 都需要调用一次 OpenGL ES绘图,这是低效率的.
*
*
* Limitations:
* - 目前只支持 ParticleSystemQuad
* - 所有的系统都使用相同的参数被绘制 blend function, aliasing, texture
*
* 最有效的用法
* - 使用 texture,一个足够容纳所哟粒子系统的容量 初始化一个 ParticleBatchNode
* - 初始化所有粒子系统,并将其添加为批处理节点的 child
* @since v1.1
*/
class CC_DLL ParticleBatchNode : public Node, public TextureProtocol
{
public:
/** 使用 Texture2D,粒子容量,使用的粒子系统 初始化一个粒子系统 */
static ParticleBatchNode* createWithTexture(Texture2D *tex, unsigned int capacity = kParticleDefaultCapacity);
/** 使用 磁盘上的文件的名称(一个列表,列表上面是 他所支持的 Texture2D 类),k粒子容量 初始化粒子系统 */
static ParticleBatchNode* create(const char* fileImage, unsigned int capacity = kParticleDefaultCapacity);
/**
* @js ctor
*/
ParticleBatchNode();
/**
* @js NA
* @lua NA
*/
virtual ~ParticleBatchNode();
/** 使用 Texture2D,粒子容量,使用的粒子系统 初始化一个粒子系统 */
bool initWithTexture(Texture2D *tex, unsigned int capacity);
/** 使用 磁盘上的文件的名称(一个列表,列表上面是 他所支持的 Texture2D 类),k粒子容量 初始化粒子系统 */
bool initWithFile(const char* fileImage, unsigned int capacity);
/** 把一个 child 添加到 ParticleBatchNode */
void insertChild(ParticleSystem* system, int index);
void removeChildAtIndex(unsigned int index, bool doCleanup);
void removeAllChildrenWithCleanup(bool doCleanup);
/** 通过插入一个 0'd quad 到 texture atlas 来禁用某个粒子 */
void disableParticle(unsigned int particleIndex);
/** Gets the texture atlas used for drawing the quads */
inline TextureAtlas* getTextureAtlas() const { return _textureAtlas; };
/** 设置用于绘制的quads(四边形) texture atlas */
inline void setTextureAtlas(TextureAtlas* atlas) { _textureAtlas = atlas; };
// Overrides
void visit();
virtual void addChild(Node * child) override;
virtual void addChild(Node * child, int zOrder) override;
virtual void addChild(Node * child, int zOrder, int tag) override;
virtual void removeChild(Node* child, bool cleanup) override;
virtual void reorderChild(Node * child, int zOrder) override;
virtual void draw(void) override;
virtual Texture2D* getTexture(void) const override;
virtual void setTexture(Texture2D *texture) override;
/**
* @code
* 当这个函数绑定到 js or lua,输入参数会改变
* In js: var setBlendFunc(var src, var dst)
* @endcode
* @lua NA
*/
virtual void setBlendFunc(const BlendFunc &blendFunc) override;
/**
* @js NA
* @lua NA
*/
virtual const BlendFunc& getBlendFunc(void) const override;
private:
void updateAllAtlasIndexes();
void increaseAtlasCapacityTo(unsigned int quantity);
unsigned int searchNewPositionInChildrenForZ(int z);
void getCurrentIndex(unsigned int* oldIndex, unsigned int* newIndex, Node* child, int z);
unsigned int addChildHelper(ParticleSystem* child, int z, int aTag);
void updateBlendFunc(void);
/** 用于绘制的quads(四边形) texture atlas */
TextureAtlas* _textureAtlas;
private:
/** 用于绘制的quads(四边形) blend function */
BlendFunc _blendFunc;
};
// end of particle_nodes group
/// @}
NS_CC_END
#endif /* __CCPARTICLEBATCHNODE_H__ */