您的位置:首页 > 编程语言

OT源代码的分析,OrtHello 迟早攻破你 (五)OTContainer相关

2011-12-05 22:51 357 查看
OTContainers 可以看成是一个Texture管理器,每一个管理一张图片, 其实可以看成是spritesheet

OTContainers里面可以放入的内容有:OTSpriteSheet,

Atlas(包括SpriteAtlas-Base,SpriteAtlas-Cocos2D,SpriteAtlas-OGRE,SpriteAtlas-Sparrow)

最实用的可能是SpriteAtlas-Cocos2D导出的Texture和xml文件的方法。

其实前面4章讲的都是一些比较空泛又底层的东西,从这一章开始实用性会大大增加

我们打开orthello的第3个例子,可以看的比较清楚了,首先我们看到这个Containers其实是从预设的SpriteSheet里面拖拽过来的,其实在创建的时候也可以用代码,但是个人觉得如果是SpriteSheet的话既然游戏要用到,不如就先加载进来,



再看看一个Containers 具体来讲下面是一个最基本的SpriteSheet

下面讲的是重点,Frames XY 是控制整个Texture的切分程度,具体来说就是决定横向切多少个小方块,纵向切多少个小方块

方块的大小不能由程序控制,而是由切分的比例和整个Texture控制

有一个重点就是:每一个spritesheet是有相同大小的frame!

SheetSize是说整个Sheet在Texture中的大小,如果设0,0则表示整个Texture都是,如果设置了一个X和Y,那么则从Texture的左上角开始,X和Y确定的大小来作为一个真实的Texture,不得不说这种方法比较不好用。原文:If we have some empty space to the right or bottom of this texture we can specify the original SheetSize in pixels ( always in combination
with the original FrameSize in pixels ) so texture scaling and offsetting for the frames can be calculated.

FrameSize是说整个Frame在每一个被切分的sheet 中的大小,如果设0,0则表示整个Frame都是,假设每一个Frame是40*40,

但是你的FrameSize设了10,10则这个真实的frame只用到了40*40里面的10*10,它会剔除掉其他部分-_- 其实这样做有个坏处就是不规则的图形的话不好排列

原文:If we have some empty space to the right or bottom of this texture we can specify the original FrameSize in pixels ( always in combination with the original SheetSize in pixels ) so texture scaling and offsetting for the frames can be calculated.

还好有一个用xml导入cocos2d的资源的方法,这个xml相当于plist文件,好吧这个和spritesheet的方法类似,只不过要导入一个xml文件

Texture 就是选择的图片了



随便点一个OTAnimation



可以看到里面的StartFrame 和 EndFrame 就是来设置一个动作的,Fps是运行的速率,其实单单设置Duration就好了

好吧,我们继续研究OTContainer,它里面一个重要的属性Frame,看看是怎么构成的

public struct Frame

{

public string name;

public Vector2 size; /// This frame's image scale modifier

public Vector2 imageSize; /// This frame's original image size

public Vector2 offset; /// This frame's world position offset modifier

public float rotation; /// This frame's world rotation modifier

public Vector2[] uv; /// Texture UV coordinates (x/y).

public Vector3[] vertices; /// Mesh vertices used when OffsetSizing = false (Atlas)

}

public bool isReady //判断是否准备好,只有当Frame大于0时才返回true

public Frame GetFrame(int index)

public int frameCount

public virtual int GetFrameIndex(string inName)

OTSpriteSheet 继承了OTContainer,方法也大同小异

OTSpriteAtlas 也类似,多了一个offsetSizing 的属性,如果为否,则没有位置偏移和尺寸偏移,一般来说不会设置成否

OTSpriteAtlasCocos2D - - 就多了一个Atlas Data File的用来导入XML文件。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: