zoukankan      html  css  js  c++  java
  • 自定义TexturePacker插件导出自己的plist文件

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

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

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

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

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

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

    binexporters下的某一目录下存在的一个名为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,编写自己的导出插件才是王道!

  • 相关阅读:
    hdu 2602 Bone Collector 01背包
    总结
    类--接口 抽象父类 多态 鸭子类型 格式化方法与析构方法 反射 异常处理 自定义异常 断言
    类--组合 继承 super关键字 面向对象的三大性
    面向对象 名称空间 类与对象
    re正则模块 垃圾回收机制
    常用模块--hashlib hmac:加密 xml xlrd xlwt:excel读|写 configparser subprocess
    常用模块-- random shutil shevle logging sys.stdin/out/err
    常用模块-- time os sys 递归 序列化

  • 原文地址:https://www.cnblogs.com/123ing/p/3920491.html
Copyright © 2011-2022 走看看