cocos2d-X 节点(CCLabelTTF.h)API

来源:互联网 发布:地方门户网站源码 编辑:程序博客网 时间:2024/05/03 04:54

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

cocos2d-X 节点(CCLabelTTF.h)API

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

/////cocos2d-x-3.0alpha0/cocos2dx/label_nodes/****************************************************************************Copyright (c) 2010-2012 cocos2d-x.orgCopyright (c) 2008-2010 Ricardo Quesadahttp://www.cocos2d-x.orgPermission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included inall copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS INTHE SOFTWARE.****************************************************************************/#ifndef __CCLABELTTF_H__#define __CCLABELTTF_H__#include "sprite_nodes/CCSprite.h"#include "textures/CCTexture2D.h"NS_CC_BEGIN/** * @addtogroup GUI * @{ * @addtogroup label * @{ *//** @brief LabelTTF 是 TextureNode 的子类,它可以渲染 labels 的标签(label上面显示的文字)。 * * TextureNode 的所有功能在 LabelTTF 里面都是有效的 * * LabelTTF 对象非常缓慢. 可以考虑使用 LabelAtlas 、 LabelBMFont 代替. * * 自定义的 ttf 文件 可以放在  assets/ 应用程序可以访问的存储器里面 * @code * LabelTTF *label1 = LabelTTF::create("alignment left", "A Damn Mess", fontSize, blockSize,  *                                          TextHAlignment::LEFT, TextVAlignment::CENTER); * LabelTTF *label2 = LabelTTF::create("alignment right", "/mnt/sdcard/Scissor Cuts.ttf", fontSize, blockSize, *                                          TextHAlignment::LEFT, TextVAlignment::CENTER); * @endcode * */class CC_DLL LabelTTF : public Sprite, public LabelProtocol{public:    /**     * @js ctor     */    LabelTTF();    /**     * @js NA     * @lua NA     */    virtual ~LabelTTF();    /**     * @js NA     * @lua NA     */    const char* description() const;        /** 使用 fontName 、 fontSize 创建一个 LabelTTF     @since v2.0.1     */    static LabelTTF * create(const char *string, const char *fontName, float fontSize);        /** 使用 fontname, hAlignment, dimensions(以点为单位), fontSize(以点为单位)创建一个 LabelTTF     @since v2.0.1     */    static LabelTTF * create(const char *string, const char *fontName, float fontSize,                               const Size& dimensions, TextHAlignment hAlignment);      /** 使用 fontname, alignment, dimension(以点为单位) , fontSize(以点为单位)、vAlignment 创建一个 LabelTTF     @since v2.0.1     */    static LabelTTF * create(const char *string, const char *fontName, float fontSize,                               const Size& dimensions, TextHAlignment hAlignment,                                TextVAlignment vAlignment);            /** 使用 string、textDefinition 创建一个 LabelTTF */    static LabelTTF * createWithFontDefinition(const char *string, FontDefinition &textDefinition);        /**使用 fontName 、 fontSize 初始化一个 LabelTTF */    bool initWithString(const char *string, const char *fontName, float fontSize);        /** 使用 fontname, hAlignment, dimensions(以点为单位), fontSize(以点为单位)创建一个 LabelTTF */    bool initWithString(const char *string, const char *fontName, float fontSize,                        const Size& dimensions, TextHAlignment hAlignment);    /**  使用 fontname, alignment, dimension(以点为单位) , fontSize(以点为单位)、vAlignment 初始化一个 LabelTTF */    bool initWithString(const char *string, const char *fontName, float fontSize,                        const Size& dimensions, TextHAlignment hAlignment,                         TextVAlignment vAlignment);        /** 使用 string、textDefinition 初始化一个 LabelTTF */    bool initWithStringAndTextDefinition(const char *string, FontDefinition &textDefinition);        /** set 这个 label 使用的 text */    void setTextDefinition(const FontDefinition& theDefinition);        /** get 这个 label 使用的 text */    FontDefinition getTextDefinition();                /** 启用/禁用 这个 label 的阴影 */    void enableShadow(const Size &shadowOffset, float shadowOpacity, float shadowBlur, bool mustUpdateTexture = true);        /** 禁用阴影渲染 */    void disableShadow(bool mustUpdateTexture = true);        /**  启用/禁用  stroke */    void enableStroke(const Color3B &strokeColor, float strokeSize, bool mustUpdateTexture = true);        /** 启用 stroke */    void disableStroke(bool mustUpdateTexture = true);        /** 为 text 着色 */    void setFontFillColor(const Color3B &tintColor, bool mustUpdateTexture = true);            /** 初始化 LabelTTF */    bool init();    /** 创建一个 label.     */    static LabelTTF * create();    /**修改要渲染的字符串    * @warning 改变字符串是昂贵的像创建一个 LabelTTF 一样. 为了获得更好的性能建议使用LabelAtlasTo    */    virtual void setString(const char *label);    virtual const char* getString(void) const;        TextHAlignment getHorizontalAlignment() const;    void setHorizontalAlignment(TextHAlignment alignment);        TextVAlignment getVerticalAlignment() const;    void setVerticalAlignment(TextVAlignment verticalAlignment);        const Size& getDimensions() const;    void setDimensions(const Size &dim);        float getFontSize() const;    void setFontSize(float fontSize);        const char* getFontName() const;    void setFontName(const char *fontName);    private:    bool updateTexture();protected:        /** set 这个 label 使用的 text */    void _updateWithTextDefinition(const FontDefinition& textDefinition, bool mustUpdateTexture = true);    FontDefinition    _prepareTextDefinition(bool adjustForResolution = false);        /** label 的尺寸(以点为单位) */    Size _dimensions;    /** 这个 label 的对齐方式 */    TextHAlignment         _alignment;    /**垂直对齐的标签 */    TextVAlignment _vAlignment;    /** 这个 label 使用的字体名 */    std::string * _fontName;    /** Font size of the label */    float _fontSize;    /** label's string */    std::string _string;        /** 字体阴影 */    bool    _shadowEnabled;    Size    _shadowOffset;    float   _shadowOpacity;    float   _shadowBlur;            /** font stroke */    bool        _strokeEnabled;    Color3B     _strokeColor;    float       _strokeSize;            /** font tint */    Color3B   _textFillColor;    };// end of GUI group/// @}/// @}NS_CC_END#endif //__CCLABEL_H__







原创粉丝点击