CCLabelBMFont解析

CCLabelBMFont


代码:

/** @brief LabelBMFont is a subclass of SpriteBatchNode.
LabelBMFont是SpriteBatchNode的子类
Features:
- Treats each character like a Sprite. This means that each individual character can be:
- rotated
- scaled
- translated
- tinted
- change the opacity
- It can be used as part of a menu item.
- anchorPoint can be used to align the "label"
- Supports AngelCode text format
特点:
- 将每一个字符处理为一个精灵。这就意味着每一个独特的字符都能:旋转,缩放,变化,着色,改变透明度,设置锚点,支持天使码文本格式
Limitations:
- All inner characters are using an anchorPoint of (0.5f, 0.5f) and it is not recommend to change it
because it might affect the rendering
所有内部的字符使用的锚点都是(0.5f,0.5f),不建议改变他,因为,这将影响到渲染

LabelBMFont implements the protocol LabelProtocol, like Label and LabelAtlas.
LabelBMFont想Label和LabelAtLas一样继承了了LabelProtocol接口
LabelBMFont has the flexibility of Label, the speed of LabelAtlas and all the features of Sprite.
LabelBMFont有Label的灵活性,LabelAtLas的渲染速度和精灵所有的特点。
If in doubt, use LabelBMFont instead of LabelAtlas / Label.
如有有疑问,使用LabelBMFont代替LableAtLas和Labe
Supported editors://支持的编辑器
http://glyphdesigner.71squared.com/ (Commercial, Mac OS X)
http://www.n4te.com/hiero/hiero.jnlp (Free, Java)
http://slick.cokeandcode.com/demos/hiero.jnlp (Free, Java)
http://www.angelcode.com/products/bmfont/ (Free, Windows only)

@since v0.8
*/

class CC_DLL CC_DEPRECATED_ATTRIBUTE LabelBMFont : public Node, public LabelProtocol, public BlendProtocol
{
public:
    /**
     * @js ctor
     */
    LabelBMFont();
    /**
     * @js NA
     * @lua NA
     */
    virtual ~LabelBMFont();

    /** creates a bitmap font atlas with an initial string and the FNT file */
	// 创建一个LabelBMFong对象
    static LabelBMFont * create(const std::string& str, const std::string& fntFile, float width = 0, TextHAlignment alignment = TextHAlignment::LEFT,const Vec2& imageOffset = Vec2::ZERO);

    /** Creates an label.
     */
    static LabelBMFont * create();

    /** init a bitmap font atlas with an initial string and the FNT file */
	// 初始化
    bool initWithString(const std::string& str, const std::string& fntFile, float width = 0, TextHAlignment alignment = TextHAlignment::LEFT,const Vec2& imageOffset = Vec2::ZERO);

    // super method
	// 设置字符串
    virtual void setString(const std::string& newString) override;
	// 得到字符串
    virtual const std::string& getString() const override;
	// 设置队列模式
    virtual void setAlignment(TextHAlignment alignment);
	// 设置宽度
    virtual void setWidth(float width);
	// 在空格处设置换行
    virtual void setLineBreakWithoutSpace(bool breakWithoutSpace);
    
    // RGBAProtocol 
	// 是不是支持透明度修改颜色
    virtual bool isOpacityModifyRGB() const override;
	// 设置透明度修改颜色
    virtual void setOpacityModifyRGB(bool isOpacityModifyRGB) override;
	// 设置字体文件
    void setFntFile(const std::string& fntFile, const Vec2& imageOffset = Vec2::ZERO);
    // 得到字体文件
	const std::string& getFntFile() const;
// 设置混合函数
    virtual void setBlendFunc(const BlendFunc &blendFunc) override;
// 得到混合函数
    virtual const BlendFunc &getBlendFunc() const override;
// 得到字符
    virtual Sprite * getLetter(int ID);
	
    virtual Node * getChildByTag(int tag) const override;
// 设置颜色
    virtual void setColor(const Color3B& color) override;

    virtual const Size& getContentSize() const override;
    virtual Rect getBoundingBox() const override;
// 得到描述
    virtual std::string getDescription() const override;
#if CC_LABELBMFONT_DEBUG_DRAW
// 绘制
    virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override;
#endif

private:
#if CC_LABELBMFONT_DEBUG_DRAW
    DrawNode *_debugDrawNode;
#endif
    
    // name of fntFile
    std::string _fntFile;

    Label*      _label;

};


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值