代码:
/**
* @class LabelAtlas
* @brief LabelAtlas is a subclass of AtlasNode.
*LabelAtlas是一个AtlasNode的子类
* It can be as a replacement of Label since it is MUCH faster.
* 他可以代替Label,因为他更快
* LabelAtlas versus Label:
* - LabelAtlas is MUCH faster than Label.
* - LabelAtlas "characters" have a fixed height and width.字符有固定的宽高
* - LabelAtlas "characters" can be anything you want since they are taken from an image file.
* 可以是任何的样子,因为他们从图片文件中得到
* A more flexible class is LabelBMFont. It supports variable width characters and it also has a nice editor.
*LabelBMFont是一个更灵活的类,支持可变宽度的字符,还有不错的编辑器
*/
class CC_DLL LabelAtlas : public AtlasNode, public LabelProtocol
{
public:
/**
* Creates an empty LabelAtlas.
* User need to call initWithString(...) later to make this object work properly.
*/
// 创建一个LabelAtlas对象
static LabelAtlas* create();
/** Creates the LabelAtlas with a string, a char map file(the atlas), the width and height of each element and the starting char of the atlas. */
static LabelAtlas* create(const std::string& string, const std::string& charMapFile, int itemWidth, int itemHeight, int startCharMap);
/**
* Creates the LabelAtlas with a string and a configuration file.
* @since v2.0
*/
static LabelAtlas* create(const std::string& string, const std::string& fntFile);
/** Initializes the LabelAtlas with a string, a char map file(the atlas), the width and height of each element and the starting char of the atlas. */
// 初始化
bool initWithString(const std::string& string, const std::string& charMapFile, int itemWidth, int itemHeight, int startCharMap);
/**
* Initializes the LabelAtlas with a string and a configuration file.
* @since v2.0
*/
bool initWithString(const std::string& string, const std::string& fntFile);
/** Initializes the LabelAtlas with a string, a texture, the width and height in points of each element and the starting char of the atlas */
bool initWithString(const std::string& string, Texture2D* texture, int itemWidth, int itemHeight, int startCharMap);
// 设置文本
virtual void setString(const std::string &label) override;
// 得到文本
virtual const std::string& getString(void) const override;
// 更新图集的值
virtual void updateAtlasValues() override;
/**
* @js NA
*/
virtual std::string getDescription() const override;
#if CC_LABELATLAS_DEBUG_DRAW
// 绘制
virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override;
#endif
CC_CONSTRUCTOR_ACCESS:
LabelAtlas()
:_string("")
{
#if CC_LABELATLAS_DEBUG_DRAW
_debugDrawNode = DrawNode::create();
addChild(_debugDrawNode);
#endif
}
virtual ~LabelAtlas()
{
_string.clear();
}
protected:
virtual void updateColor() override;
#if CC_LABELATLAS_DEBUG_DRAW
DrawNode *_debugDrawNode;
#endif
// string to render
std::string _string;
// the first char in the char map
int _mapStartChar;
};
代码:
// @cond DO_NOT_SHOW
#include "platform/CCPlatformMacros.h"
NS_CC_BEGIN
class Label;
//标志文本格式画
class CC_DLL LabelTextFormatter
{
public:
// 多重文本
static bool multilineText(Label *theLabel);
// 拍成一排
static bool alignText(Label *theLabel);
// 创建文本精灵
static bool createStringSprites(Label *theLabel);
};