COCos2d-X 节点(CCAtlasNode.h)API

本文详细介绍了Cocos2d-X中的CCAtlasNode节点API,包括其使用和功能,旨在帮助开发者更好地理解和应用这一组件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本文来自http://blog.csdn.net/runaying ,引用必须注明出处!

COCos2d-X 节点(CCAtlasNode.h)API

温馨提醒:为了大家能更好学习,强烈推荐大家看看本人的这篇博客 Cocos2d-X权威指南笔记

///cocos2d-x-3.0alpha0/cocos2dx/base_nodes


#ifndef __CCATLAS_NODE_H__
#define __CCATLAS_NODE_H__

#include "CCNode.h"
#include "CCProtocols.h"
#include "ccTypes.h"

NS_CC_BEGIN

/**
 * @addtogroup base_nodes
 * @{
 */

class TextureAtlas;

/** @brief AtlasNode 是 Node 的子类,实现了 RGBAProtocol 、 TextureProtocol 协议

他知道如何 render(呈现)一个 TextureAtlas 对象.
如果你要 render(呈现)一个 AtlasNode 的子类 TextureAtlas (or AtlasNode 的子类)

从节点的所有功能都有效,再加上以下功能:
- opacity and RGB colors        //不透明度和RGB颜色
*/
class CC_DLL AtlasNode : public NodeRGBA, public TextureProtocol
{    
public:
	/** 使用 一个 Atlas 文件,每个 item(组成Atlas 的 tile(瓷砖)) 的宽度、高度 要显示的 items 数量 创建一个 AtlasNode */
	static AtlasNode * create(const char* tile,unsigned int tileWidth, unsigned int tileHeight,
                              unsigned int itemsToRender);
    /**
     * @js ctor
     */
    AtlasNode();
    /**
     * @js NA
     * @lua NA
     */
    virtual ~AtlasNode();

    /** 使用 一个 Atlas 文件,每个 item(组成Atlas 的 tile(瓷砖)) 的宽度、高度 要显示的 items 数量 初始化一个 AtlasNode */
    bool initWithTileFile(const char* tile, unsigned int tileWidth, unsigned int tileHeight, unsigned int itemsToRender);

    /** 使用 texture,每个 item(组成Atlas 的 tile(瓷砖)) 的宽度、高度 要显示的 items 数量 初始化一个 AtlasNode
     */
    bool initWithTexture(Texture2D* texture, unsigned int tileWidth, unsigned int tileHeight, unsigned int itemsToRender);
    
    /**更新 Atlas(地图集) (indexed vertex array).    //索引顶点数组
    * 应在子类中重写
    */
    virtual void updateAtlasValues();

    void setTextureAtlas(TextureAtlas* textureAtlas);
    TextureAtlas* getTextureAtlas() const;
    
    void setQuadsToDraw(unsigned int quadsToDraw);
    unsigned int getQuadsToDraw() const;

    
    // Overrides(覆盖)
    virtual void draw() override;
    virtual Texture2D* getTexture() const override;
    virtual void setTexture(Texture2D *texture) override;
    virtual bool isOpacityModifyRGB() const override;
    virtual void setOpacityModifyRGB(bool isOpacityModifyRGB) override;
    virtual const Color3B& getColor(void) const override;
    virtual void setColor(const Color3B& color) override;
    virtual void setOpacity(GLubyte opacity) 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() const override;

private :
    void calculateMaxItems();
    void updateBlendFunc();
    void updateOpacityModifyRGB();
    
    friend class Director;
    void setIgnoreContentScaleFactor(bool bIgnoreContentScaleFactor);

protected:
    //! 每行字符
    unsigned int _itemsPerRow;
    //! 每列的字符
    unsigned int _itemsPerColumn;

    //! 每个字符的宽度
    unsigned int    _itemWidth;
    //! 每个字符的高度
    unsigned int    _itemHeight;
    
    Color3B    _colorUnmodified;
    
    TextureAtlas* _textureAtlas;
    // 协议变量
    bool _isOpacityModifyRGB;
    BlendFunc _blendFunc;

    // 绘制的四边形
    unsigned int _quadsToDraw;
    // 颜色均匀
    GLint    _uniformColor;
    // 这仅用于显示 LabelAtlas FPS . 所以我希望大家不要修改它的值.
    bool _ignoreContentScaleFactor;
};

// end of base_node group
/// @}

NS_CC_END

#endif // __CCATLAS_NODE_H__



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值