cocos2d-x节点(CCParticleBatchNode.h)API

本文来自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__ */


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值