CCAtlasNode(CCAtlasNode封装了一个CCTextureAtlas的变量,CCTextureAtlas初始化图片文件的时候会把图片加载到缓存(CCTextureCache)中:)

----->         文字         

CCLabelTTF

CCLabelTTF对象渲染比较慢,每次调用setString的时候,一个新的OpenGL纹理将被创建,这意味着setString和创建一个新的标签一样慢,所以当需要频繁更新label的时候,应该选择另外两种文字类。 


CCLabelBMFont   可以表现任意包括中文(精灵纹理 位图字体

它是CCSpriteSheet的一个子类,对每一个字符就像一个CCSprite来对待,因此每个单独的字符可以进行旋转、缩放、设置透明等操作。

使用该类之前,需要添加好字体文件,包括一个图片文件(AA.png)和一个字体坐标文件(AA.fnt)。两个文件的名称相同,只是扩展名不同。
CCLabelBMFont的改变相当于每次只改变图片坐标。

CCLabelBMFont中每个文字相当于一个CCSprite,可以旋转,移动,改变尺寸等

绘制字符串时,根据字符对应的unicode码去查找ccBMFontDef信息,从缓存中取出图片,再根据ccBMFontDef中坐标、宽高取出对应区域的字符图片,把字符在字符串中的索引位置作为tag添加到CCLabelBMFont中,因为CCLabelBMFont本身是CCSpriteBatchNode,这样就实现了批处理渲染精灵,提高了性能。


CCLabelAtlas  只可表现256个字符

这个类会将传入的图片“分成”指定宽高的小块,根据需要获得字符的ASCII与startCharMap指定的图中的第一个字符的ASCII计算偏移量,取得对应的小块。这就需要图片中的字符是按照ASCII的顺序连续排列的。 

CCLabelAtlas:也是CCAtlasNode的子类,参数的含义:要绘制的字符,图片文件,图片文件中每个字符的宽度,图片文件中每个字符的高度,图片的起始字符。



CCAtlasNode封装了一个CCTextureAtlas的变量,CCTextureAtlas初始化图片文件的时候会把图片加载到缓存(CCTextureCache)中:


接下来CCTextureAtlas负责管理该大图,可以随意绘制图片的某一矩形区域,渲染方式采用的是OpenGL ES VBO(顶点缓冲对象,保存在显存中)。 CCTextureAtlas有一个m_pQuads属性,它是CCTextureAtlas类的核心,是一个ccV3F_C4B_T2F_Quad类型的数组,ccV3F_C4B_T2F_Quad是一个结构体,有四个成员属性,它们都是ccV3F_C4B_T2F类,分别表示左上,左下,右上,右下。



#ifndef __CCATLAS_NODE_H__

#define __CCATLAS_NODE_H__


#include "CCNode.h"

#include "CCProtocols.h"

#include "ccTypes.h"


NS_CC_BEGIN


class CCTextureAtlas;

1.COCos2d-X 节点(CCAtlasNode.h)API AtlasNode 是 Node 的子类,实现了 RGBAProtocol 、 TextureProtocol 协议
节点的所有功能都有效,再加上以下功能:
- opacity and RGB colors //不透明度和RGB颜色

/** @brief CCAtlasNode is a subclass(子集) of CCNode that implements(工具) the CCRGBAProtocol and CCTextureProtocol protocol(协议)


It knows how to render a TextureAtlas object.

If you are going to render a TextureAtlas consider(考虑) subclassing CCAtlasNode (or a subclass of CCAtlasNode)


All features from CCNode are valid(有效地), plus the following features:

- opacity and RGB colors

*/

class CC_DLL CCAtlasNode : public CCNodeRGBA, public CCTextureProtocol

{

protected:


    //! chars per row

    unsigned int m_uItemsPerRow; //每行字符

    //! chars per column

    unsigned int m_uItemsPerColumn; //每列字符


    //! width of each char

    unsigned int    m_uItemWidth; //每个字符width

    //! height of each char

    unsigned int    m_uItemHeight; //每个字符height


    ccColor3B    m_tColorUnmodified;


    CC_PROPERTY(CCTextureAtlas*, m_pTextureAtlas, TextureAtlas);  // CCTextureAtlas get set方法


    // protocol variables

    bool m_bIsOpacityModifyRGB;

    

    CC_PROPERTY(ccBlendFunc, m_tBlendFunc, BlendFunc);  //gl的 blendfunc接口


    // quads to draw

    CC_PROPERTY(unsigned int, m_uQuadsToDraw, QuadsToDraw); //渲染接口

    // color uniform

    GLint    m_nUniformColor;

    // This varible is only used for CCLabelAtlas FPS display. So plz don't modify its value.

    bool m_bIgnoreContentScaleFactor;

    

public:

    CCAtlasNode();

    virtual ~CCAtlasNode();


/** creates a CCAtlasNode  with an Atlas file the width and height of each item and the quantity of items to render*/

static CCAtlasNode * create(const char* tile,unsigned int tileWidth, unsigned int tileHeight, 

unsigned int itemsToRender);


    /** initializes an CCAtlasNode  with an Atlas file the width and height of each item and the quantity of items to render*/

    bool initWithTileFile(const char* tile, unsigned int tileWidth, unsigned int tileHeight, unsigned int itemsToRender);


    /** initializes an CCAtlasNode  with a texture the width and height of each item measured in points and the quantity of items to render*/

    bool initWithTexture(CCTexture2D* texture, unsigned int tileWidth, unsigned int tileHeight, unsigned int itemsToRender);

    

    /** updates the Atlas (indexed vertex array).

    * Shall be overridden in subclasses

    */

    virtual void updateAtlasValues();


    virtual void draw(void);


    // CC Texture protocol


    /** returns the used texture*/

    virtual CCTexture2D* getTexture(void);


    /** sets a new texture. it will be retained*/

    virtual void setTexture(CCTexture2D *texture);

    

    virtual bool isOpacityModifyRGB();

    virtual void setOpacityModifyRGB(bool isOpacityModifyRGB);

    virtual const ccColor3B& getColor(void);

    virtual void setColor(const ccColor3B& color);

    virtual void setOpacity(GLubyte opacity);


private :

    void calculateMaxItems();  //最大字符数

    void updateBlendFunc();

    void updateOpacityModifyRGB();

    

    friend class CCDirector;

    void setIgnoreContentScaleFactor(bool bIgnoreContentScaleFactor);

};


// end of base_node group

/// @}


NS_CC_END


#endif // __CCATLAS_NODE_H__



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值