您的位置:首页 > 移动开发 > Cocos引擎

COCos2d-X 节点(CCAtlasNode.h)API

2013-12-09 10:40 190 查看
本文来自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__
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: