自定义TexturePacker插件导出自己的plist文件

摘要:
原始地址:http://www.cppblog.com/sunicdavy/archive/2014/02/06/205645.htmlcocos2dx该引擎使用plist文件(一种特殊的xml格式)作为其图集纹理描述文件。plist在xml中遵循了苹果的关键价值设计风格。它适用于OC,但xml本身性能低,垃圾内容太多,这使得plist不再适用于高性能游戏引擎。因此,研究Tex

原地址: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,编写自己的导出插件才是王道!

免责声明:文章转载自《自定义TexturePacker插件导出自己的plist文件》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇eclipse导入maven项目有红叉及pom.xml出错的问题的解决visdom使用下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

如何使用TexturePacker

去下载一个破解版本的TP(以下简称TP),打开应用,界面如图所示。     * 通过Add Folder来添加图片进来,增加文件夹的方式来增加精灵后,Texture Packer并不是对每一个精灵增加一个索引  (reference),而是对整个文件夹增加了一个索引。这意味着,当你以后向这个文件夹中增加精灵之后,下一次你运行Texture Packer的时...

cocostudio使用plist创建序列帧动画图片名称序列错乱的问题

cocostudio 版本v2.2.9 用texturePacker将动画帧打包成一个plist和一张png,将plist拖入cocostudio中的资源栏中。 如图所示,plist里面的图片顺序是乱掉的,而且该顺序无法调整,10,11应该在最后,这样选择这11张图创建的序列帧动画中间2帧将是错乱的 如果自己手动调整关键帧很麻烦,那么解决问题的地方就在于...