将TexturePacker集成到XCode

TexturePacker: http://www.codeandweb.com/texturepacker

将TexturePacker集成到XCode,有一个好处,就是你不再需要将生成的png大图上传到svn或者github了。

如果英文允许的话,建议参考本文最后的参考文章链接。

1、项目结构图



 

多说一句,其实Assets目录不需要添加到Project中去,因为所有的资源都已经生成到plist, png文件中了。上图作为一个目录结构参考更合适。

2、shell脚本

使用TexturePacker命令来生成相应的png资源

#! /bin/sh
TP=/usr/local/bin/TexturePacker
if [ "${ACTION}" = "clean" ]
then
# remove sheets - please add a matching expression here
rm ../Resources/sheet*.png
rm ../Resources/sheet*.plist
else
# create all assets from tps files
${TP} *.tps
fi

exit 0

 如果需要生成不同尺寸的资源,例如ipadHD和ipad的

#! /bin/sh
TP=/usr/local/bin/TexturePacker
if [ "${ACTION}" = "clean" ]
then
# remove all files
rm ../Resources/sheet*.png
rm ../Resources/sheet*.plist
else
# create hd & sd assets
${TP} --smart-update sheet1 \
--auto-sd \
--format cocos2d \
--data ../Resources/sheet-hd.plist \
--sheet ../Resources/sheet-hd.png
 
# create ipad assets from same sprites
${TP} --smart-update --scale 1.066 sheet1 \
--format cocos2d \
--data ../Resources/sheet-ipad.plist \
--sheet ../Resources/sheet-ipad.png
 
... add more sheets ....
fi
exit 0

对于文中的参数含义,可以通过命令

/usr/local/bin/TexturePacker --help

 来查看。

3、将shell脚本集成到XCode5

如果你用的XCode4,建议查看文章最后的参考文章链接。


 在弹出的模板界面中的选择Other/External Build System



 配置好New Target的Info后,添加Target Dependencies


 That's all.

更详细步骤参考以下链接。

参考文章:

Tutorial: XCode4 integration of TexturePacker for Cocos2d and Sparrow framework

猜你喜欢

转载自song020cn.iteye.com/blog/1980789