plist格式说明清好好

来源:互联网 发布:万方数据库系统 编辑:程序博客网 时间:2024/05/10 05:15

cocos2d-x中的plist文件格式详解

本文完成度90%,请耐心等待……


1. 什么是plist文件格式?

这是一种人类可读的串行化对象文件,由苹果公司发明,最早用于NeXTSTEP系统。详情看这里:Plist 。

cocos2d-x 从 cocos2d-iphone 发展而来,因此在引擎中大量使用了这种文件格式。

2. 如何编辑plist文件?

在 OS X 系统上,XCode 就可以直接打开和编辑plist文件。而在Windows上,我还没有找到可用的plist编辑软件。

当然,plist是基于XML的纯文本格式,随便找个文本编辑器就可以编辑了。

3. cocos2d-x在哪些地方使用了plist格式?

大致有这样几种:

  • 图像纹理定义文件
    将多个纹理拼在一张大图上,使用 CCSpriteFrameCache 可以载入这类plist文件;
    这里有一个图像纹理定义文件的范例: [cocos2d-x]\samples\Cpp\TestCpp\Resources\animations\grossini_family.plist 。
  • Label纹理定义文件
    作用与图像纹理定义文件类似,只不过处理的是自己,面向CCLabelAtlas
    这里有一个Label纹理定义文件的范例: [cocos2d-x]\samples\Cpp\TestCpp\Resources\fonts\tuffy_bold_italic-charmap.plist 。
  • 帧动画定义
    定义一个或多个动画中,使用哪些纹理,使用CCAnimationCache 可以载入这类plist文件;
    这里有一个帧动画定义文件的范例: [cocos2d-x]\samples\Cpp\TestCpp\Resources\animations\animations.plist 。

4. 生成plist文件的工具

对于纹理定义文件来说,它的作用是如何在大图中找到碎图的坐标。因此很多拼合碎图的软件可以在拼合碎图的同时生成plist文件。

  • TexturePacker 是所有平台上最好用的工具了;
  • Zwoptex 是MAC Only的软件,我不太喜欢用;
  • SpritePacker 是Windows Only的软件,功能尚可。

5. 图像纹理定义文件格式说明

cocos2d-x中的纹理定义格式,是以Zwoptex生成的格式为标准的。

Zwoptex生成的格式,有4种主要不同的版本:

  • format值为0,代表Flash版本;
  • format值为1,Zwoptex 0.4b以前支持;
  • format值为2,Zwoptex 1.0以后支持,与format1的区别在于支持旋转;
  • format值为3,属性名称进行了大幅修改,Zwoptes1.0.2之后支持。

这3种格式的plist文件,cocos2d-x都能支持,具体的解析代码在CCSpriteFrameCache::addSpriteFramesWithDictionary

TexturePacker生成的for cocos2d plist格式与Zwoptex生成的format为2的格式相同。

5.1 format为0的plist文件

这里贴一个比较完整plist文件,为了方便描述,其中仅包含一个frame。

5.2 format为2的plist文件内容

5.3 format为3的plist文件内容

Frame:

Top-Left originating rectangle of the sprite’s pixel texture coordinates. Cocos2′d will convert these to UV coordinates (0-1) when loading based on the texture size.

Offset:

Zwoptex trim’s transparency off sprites. Because of this sprite’s need to be offset to ensure their texture is drawn in correct alignment to their original size.

Source Color Rect:

This is the Top-Left originating rectangle that is the valid pixel data of the sprite. Say you have a 512×512 sprite that only has 10×10 pixels of data inside of it located at 500×500. The source color rect could be {500,500,10,10}.

Format:

Version number related to what version of Zwoptex was used so cocos2d knows how to parse the plist properly.

Flash Version: 0

Desktop Version 0-0.4b: 1

Desktop Version 1.x: 2

In general if you’re not trimming images you can set offset to be 0,0 and sourceColorRect to 0,0,frame.size.width,frame.size.height.

http://www.cocos2d-iphone.org/forums/topic/zwoptex-and-their-plist-explanation/

5. Label纹理定义文件

对这种格式的具体的解析代码在 CCLabelAtlas::initWithString

6. 帧动画定义文件格式说明

详见 Cocos2d-x 中的帧动画

COCOS2D-XPLISTXML

文章导航

0 0