Cocos2d API解析之TextureAtlas

TextureAtlas
(以下内容是:cocoachina的猪头解释的,原贴在:http://www.cocoachina.com/bbs/read.php?tid-8261.html)
供AtlasSpriteManager与AtlasSprite的材质类
从Texture2D继承而来,在其基础上增加了一个非常重要的成员变量
ccV3F_C4B_T2F_Quad *  quads
实际上AtlasSprite相比Sprite能快更得进行大批量渲染也是因为这个
TextureAtlas维护了一个ccV3F_C4B_T2F_Quad数组,使用一张texture进行batch render
其他与Texture2d没什么不同

这个过程是这样的:
1.首先是AtlasSpriteManager使用一张TextureAtlas初始化,并设定Quad数组的长度
2.往AtlasSpriteManager加入AtlasSprite,这个加入的过程其实只是往AtlasSpriteManager的Quad数组中更新一个Quad
3.渲染的时候使用一张Texture根据Quad数组中的不同值一个个渲染

支持的特征有:
1、地图集文件可以是PVRTC PNG 或者其他Texture2D支持的格式;
2、四边形可以在运行期间被添加、移除、重新排序
3、TextureAtlas 的capacity(包括ccV3F_C4B_T2F_Quad数组的容器)能够在运行期被增加或减少
4、OpenGL的组件:V3F,C4B,T2F
呈现的四边形是使用OpenGL ES的交错的顶点数组列表

textureAtlas = [[TextureAtlas textureAtlasWithFile: @"atlastest.png" capacity:3] retain];
//创建一个TextureAtlas ,capacity表示初始化ccV3F_C4B_T2F_Quad数组的长度
    ccV3F_C4B_T2F_Quad quads[] = {
        {
          //{{顶点坐标}, {顶点颜色},{顶点UV坐标}}
            {{0,0,0},{0,0,255,255},{0.0f,1.0f},},                // bottom left
            {{s.width,0,0},{0,0,255,0},{1.0f,1.0f},},            // bottom right
            {{0,s.height,0},{0,0,255,0},{0.0f,0.0f},},            // top left
            {{s.width,s.height,0},{0,0,255,255},{1.0f,0.0f},},    // top right
        },       
        {
            {{40,40,0},{255,255,255,255},{0.0f,0.2f},},            // bottom left
            {{120,80,0},{255,0,0,255},{0.5f,0.2f},},            // bottom right
            {{40,160,0},{255,255,255,255},{0.0f,0.0f},},        // top left
            {{160,160,0},{0,255,0,255},{0.5f,0.0f},},            // top right
        },

        {
            {{s.width/2,40,0},{255,0,0,255},{0.0f,1.0f},},        // bottom left
            {{s.width,40,0},{0,255,0,255},{1.0f,1.0f},},        // bottom right
            {{s.width/2-50,200,0},{0,0,255,255},{0.0f,0.0f},},        // top left
            {{s.width,100,0},{255,255,0,255},{1.0f,0.0f},},        // top right
        },
       
    };

LabelAtlas

LabelAtlas是一个 AtlasNode的类
LabelAtlas可以替代标签,因为它比标签快得多

  • 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 

BitmapFontAtlas is a subclass of AtlasSpriteManger.

Features:

  • Treats each character like an AtlasSprite. This means that each individual character can be:(它可实现AtlasSpriter的诸多功能)
    • rotated
    • scaled
    • translated
    • tinted
    • chage the opacity
  • It can be used as part of a menu item.
  • anchorPoint can be used to align the "label"
  • Supports Hiero format (http://slick.cokeandcode.com/demos/hiero.jnlp)


FNT文件是微软为应用软件编写的一种字体文件,也就是DOS时期所说的字库文件。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值