巧用TexturePacker命令行,与ant集成

来源:互联网 发布:wingide5 linux 破解 编辑:程序博客网 时间:2024/06/08 20:02

TexturePacker做的非常出色,打包纹理,制作spritesheet的首选利器,它的完美还体现在视图与命令的分离,提供了完善的命令行工具,功能完全覆盖了界面所提供的功能,而且效率更快。

相信做技术的还是最喜欢使用命令行功能,因为其可以配合一些脚本完全避免掉琐碎的手工操作,能批量操作,方面素材重构及整理,比如每次有资源更新,需要收到打开.tps文件,然后在publish,文件少了无所谓,如果有一大推文件需要调整,那估计就显得重复而枯燥了。


关于其命令行的官方文档,已讲得非常清晰:http://www.codeandweb.com/texturepacker/documentation


下面给出命令行的两种使用方式:

1、方式一:TexturePacker  **.tps

此种方式适用于你已经使用TexturePacker  GUI制作了一个tps文件,使用此行命令直接发布结果。他所做的事相当于:点开TexturePacker, open xxx.tps文件, 再点击publish,这样对比一看是不是非常省事。

         如果你有一大推这种tps文件,那使用一个脚本,遍历出所有的tps文件,执行此行命令即可一键更新所有资源。如下行命令:

find . -name "*.tps" | xargs TexturePacker


2、方式二:如果不想手动制作tps,也是可行的,下面给出一个集成到ant中的使用,大家一看便知:

<?xml version="1.0" encoding="UTF-8"?><project name="Asset Packager" default="main"><!--Description: 素材打包工具 --><!--Author: terran.tian@foxmail.com --><!--Date: 2013年12月18日 下午3:54:52 --><property name="ant_dir" location="antlib"/>    <path id="classpath"><fileset dir="${ant_dir}" includes="**/*.jar"/></path><taskdef resource="net/sf/antcontrib/antlib.xml" classpathref="classpath"/><property name="resRoot" value="../assets/res"/><property name="plistRoot" value="${resRoot}/plists"/><property name="packageRoot" value="${resRoot}/package"/><macrodef name="sheet">   <attribute name="folderName"/>   <attribute name="outFolder" default=""/>   <attribute name="multipack" default="false"/>   <sequential><delete dir="temp"/><copy todir="temp/res/@{folderName}">    <fileset dir="${packageRoot}/@{folderName}">        <include name="**/*.png"/>        <include name="**/*.jpg"/>    </fileset></copy><if>     <equals arg1="@{multipack}" arg2="false"/>     <then><exec executable="TexturePacker"><arg line="--format cocos2d --data temp/@{folderName}.plist        --sheet temp/@{folderName}.png   --opt RGBA8888 --dither-fs-alpha   --max-width 2048 --max-height 2048 --size-constraints POT   --border-padding 0 --shape-padding 0   --algorithm MaxRects --maxrects-heuristics Best   --disable-rotation --trim-mode Trim temp"/></exec><delete dir="temp/res/@{folderName}"/><copy todir="${plistRoot}/@{outFolder}">    <fileset dir="temp" includes="*.*"></fileset></copy><delete dir="temp"/>     </then>     <else>         <exec executable="TexturePacker"><arg line="--format cocos2d --data temp/@{folderName}{n}.plist        --sheet temp/@{folderName}{n}.png   --opt RGBA8888 --dither-fs-alpha   --max-width 2048 --max-height 2048 --size-constraints POT   --border-padding 0 --shape-padding 0   --algorithm MaxRects --maxrects-heuristics Best   --disable-rotation --trim-mode Trim --multipack temp"/></exec><delete dir="temp/res/@{folderName}"/><copy todir="${plistRoot}/@{outFolder}/@{folderName}">    <fileset dir="temp" includes="*.*"></fileset></copy><delete dir="temp"/>     </else></if>   </sequential></macrodef><target name="main">    <sheet folderName="buildingIcon"/>    <sheet folderName="scienceIcon"/>    <sheet folderName="soldierIcon"/>    <sheet folderName="componets"/>    <sheet folderName="ui" multipack="true"/>    <sheet folderName="head"/>    <sheet folderName="battleUI" multipack="true"/></target></project>

ant中定义了一个宏 sheet,folderName为需要打包的目录名(打包会遍历该目录以及其子目录下得所有png,jpg),outFolder为导处路径,multipack等于ture时,表示该目录的素材可以打到不止一张纹理上,适用于图片资源过多,而一张纹理又放不下的情况,导出的纹理名字会有序号标示。

0 0
原创粉丝点击