原地址:http://www.cppblog.com/sunicdavy/archive/2014/02/06/205645.html

cocos2dx引擎使用plist文件, 一种特殊的xml格式作为其atlas纹理的描述文件. plist遵循苹果的xml中key-value的设计风格.对于OC来说是合适的, 但xml本身性能低下, 垃圾内容过多, 也让plist对于高性能游戏引擎不再适合. 因此, 研究TexturePacker的导出插件技术

TexturePacker的自定义插件目录位于其安装目录的bin\exporters\下, 但有一些插件属于内建支持, 例如cocos2dx的plist格式, 因此无法找到对应插件

本人参考shiva3d插件, 对应导出界面的DataFormat中的Shiva3D, 快速学会了如何导出

官方文档位于http://www.codeandweb.com/texturepacker/documentation/#customization

插件的基本格式及原理是:

bin\exporters\下的某一目录下存在的一个名为exporter.xml文件作为插件的描述,例如:

<exporter version="1.0">
    <!-- identifier of the exporter -->
    <name>shiva3d</name>
 
    <!-- display name of the exporter for the combo box -->
    <displayName>Shiva3D</displayName>
    
    <!-- description of the exporter -->
    <description>Exporter for Shiva3D.</description>
 
    <!-- exporter version -->
    <version>1.0</version>
    
    <!-- currently only one file allowed - more to come with update -->
    <files>
        <file>
            <!-- name of this file variable -->
            <name>xml</name>
 
            <!-- human readable name (for GUI) -->
            <displayName>XML</displayName>
 
            <!-- file extension for the file -->
            <fileExtension>xml</fileExtension>
 
            <!-- name of the template file -->
            <template>shiva.xml</template>
        </file>
    </files>
 
    <!-- target framework supports trimming -->
    <supportsTrimming>false</supportsTrimming>
 
    <!-- target framework supports rotated sprites -->
    <supportsRotation>true</supportsRotation>
 
    <!-- rotated sprites direction (cw/ccw) -->
    <rotationDirection>cw</rotationDirection>
 
    <!-- supports npot sizes -->
    <supportsNPOT>true</supportsNPOT>
 
    <!-- supports file name stripping (remove .png etc) -->
    <supportsTrimSpriteNames>yes</supportsTrimSpriteNames>
 
    <!-- supports texure subpath -->
    <supportsTextureSubPath>yes</supportsTextureSubPath>
 
</exporter>
 
 

在Template字段中, 描述同目录的导出文件格式模板. TexturePacker使用一种叫Grantlee的模板引擎,类似于Python使用的Django模板引擎, 文档参见:Grantlee Documentation. 简单的文本格式可以参考shiva.xml快速学会

这里我们使用protobuf的文本格式(极为类似json)导出plist, 下面是导出模板

{% for sprite in allSprites %}
Sprite {
    Name: "{{sprite.trimmedName}}"
    FrameX: {{sprite.frameRect.x}}
    FrameY: {{sprite.frameRect.y}}
    FrameWidth: {{sprite.frameRectWithoutRotation.width}}
    FrameHeight: {{sprite.frameRectWithoutRotation.height}}
    OffsetX: {{sprite.cornerOffset.x}}
    OffsetY: {{sprite.cornerOffset.y}}
    OriginalWidth: {{sprite.untrimmedSize.width}}
    OriginalHeight: {{sprite.untrimmedSize.height}}
    {% if sprite.rotated %}Rotated: true {% endif %}
}
{% endfor %}

导出的结果类似于:

 
Sprite {
    Name: "car01"
    FrameX: 100
    FrameY: 129
    FrameWidth: 76
    FrameHeight: 47
    OffsetX: 0
    OffsetY: 0
    OriginalWidth: 76
    OriginalHeight: 47
    Rotated: true 
}
 
Sprite {
    Name: "car02"
    FrameX: 100
    FrameY: 51
    FrameWidth: 76
    FrameHeight: 47
    OffsetX: 0
    OffsetY: 0
    OriginalWidth: 76
    OriginalHeight: 47
    Rotated: true 
}

...

导出插件还支持js扩展, 具体内容请继续参考官方文档, 但对于简单的文本格式, 这种方式已经足够了

对比plist后, 发现plist中的垃圾信息极为多, 而且作为spriteframe的name居然带有扩展名...  因此脱离plist,编写自己的导出插件才是王道!

自定义TexturePacker插件导出自己的plist文件的更多相关文章

  1. Eclipse插件(导出UML图,打开文件资源管理器插件,静态代码分析工具PMD,在eclipse上安装插件)

    目录 能够导出UML图的Eclipse插件 打开文件资源管理器插件 Java静态代码分析工具PMD 如何在eclipse上安装插件 JProfiler性能分析工具 从更新站点安装EclEmma 能够导 ...

  2. iOS开发——UI基础-懒加载,plist文件,字典转模型,自定义view

    一.懒加载 只有使用到了商品数组才会创建数组 保证数组只会被创建一次 只要能够保证数组在使用时才创建, 并且只会创建一次, 那么我们就称之为懒加载 lazy - (void)viewDidLoad 控 ...

  3. [How to]如何自定义plist文件和读取plist文件内容

    1.简介 plist作为IOS的固化文件,就好比java中properties文件,但是在IOS中plist是可读写的. 本文将介绍自定义静态的plist文件. 2.自定义静态plist文件 右击你的 ...

  4. 还原TexturePacker plist 文件以及图片的方法 (切开各小图片)

    原地址:http://blog.csdn.net/linuxchen/article/details/16865645 Python 脚本:(来自网络) unpack_plist.py 命令行: py ...

  5. cocostudio导出plist文件

    今天在用Armature类时用到cocostudio导出文件,由于美术的原因他使用的是中文命名法(这你敢相信),后面在导入程序中跟了下代码发现是解析plist文件有误,我就来比较正常功能文件和有错文件 ...

  6. iOS 打包.framework(包括第三方、图片、xib、plist文件)详细步骤及需要注意的地方

    https://www.cnblogs.com/yk123/p/9340268.html // 加载自定义名称为Resources.bundle中对应images文件夹中的图片// 思路:从mainb ...

  7. 自定义Fiddler插件二

    在之前博客自定义Fiddler插件一中主要是实现了IRequestInspector2接口,这个接口主要是针对单个请求的,在写接口测试案例的时候也是对一个接口进行处理,如果想批量进行操作,那就可以使用 ...

  8. 自定义Fiddler插件一

    上个月自定义了一个Fiddler的插件,可以根据请求生成接口自动化测试的RF和Python代码,这样测试人员只需要手动操作页面用Fiddler抓取报文,就可以直接生成RF.Python代码,然后只需要 ...

  9. 【转】JQuery插件ajaxFileUpload 异步上传文件(PHP版)

    前几天想在手机端做个异步上传图片的功能,平时用的比较多的JQuery图片上传插件是Uploadify这个插件,效果很不错,但是由于手机不支持flash,所以不得不再找一个文件上传插件来用了.后来发现a ...

随机推荐

  1. python 遍历文件夹

    import os import os.path rootdir = “d:\data” # 指明被遍历的文件夹 for parent,dirnames,filenames in os.walk(ro ...

  2. desin pattern

    uml tool http://cruise.site.uottawa.ca/umple/ http://www.umldesigner.org/download/ http://www.eclips ...

  3. HTML5 API 之 history

    *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !important; } /* ...

  4. oracle 查询今天哪个表增加的数据多

    一.创建一个表  create table A(  TABLE_NAME VARCHAR2(200),  COUNT_NUM  NUMBER) 二.创建一个存储过程create or replace  ...

  5. hdu 5199 Gunner

    原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=5199 简单题,stl水之... #include<algorithm> #include& ...

  6. bzoj 1269 [AHOI2006]文本编辑器editor

    原题链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1269 伸展树的运用,如下: #include<cstdio> #include ...

  7. html5 shiv

    使用html5标签吧!ie6.ie7.ie8不支持怎么办?它的原理是如此的简单:    1.document.createElement("ele");  // js虚拟创建一个元 ...

  8. MVC4.0 WebApi如何自定义返回数据类型

    1.客户端可以通过HTTP Accept消息头来通知服务器客户端想要什么样的MIME类型数据,例如:application/json则代表告诉服务器想要的是Json数据 2.服务器端撇开客户端的请求类 ...

  9. 位bit——字节Byte???

    1.换算 每8个位(bit)组成一个字节(byte) 位bit简写为小写字母“b”,字节Byte简写为大写字母“B” 8*b=1*B 1024*B=1*KB 1024*K=1MB 2.举例 一个英文字 ...

  10. 一个关于C#中基类与接口混合继承的疑问总结

    思路参照 http://www.cnblogs.com/allenlooplee/archive/2004/11/16/64553.html,对原文进行了简化和补充,感谢原作者. 问题很简单,如下所示 ...