TexurePacker

设想一下,一个游戏有N多图片资源,分为M个文件夹,手动使用TexurePacker打图实在是一个体力活,同时还有忙中出乱的风险。使用脚本批量处理是不二的选择(当前环境为mac)

1.安装 TexturePacker 然后安装 TexturePacker Command Line Tool

"install图片"
如上图所示,安装 TexturePacker Command Line Tool

2.打开Teminal 输入 TexturePacker

"Teminal图片"
​ 1.检查是否安装成功
​ 2.细看 Options:内容的 Output:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
--sheet <filename>   要输出的文件的名字       Name of the sheet to write, see texture-format for formats available
--texture-format <id> 要输出的图片格式 png、pvr2、pvr2gz、jpg 等 Sets the format for the textures.
--data <filename> plist文件的名字 Name of the data file to write
--format <format> 类型 cocos2d 、unity 等 Format to write, default is cocos2d
--force-publish 忽略hash_key 每次都强制从新输出 Ignore smart update hash and force re-publishing of the files
--texturepath <path> 输出路径 Adds the path to the texture file name stored in the data file.
--border-padding <int> 图片之间间隔 Sets a padding around each the border, value is in pixels, default is 2
--shape-padding <int> 图片形状间隔 Sets a padding around each shape, value is in pixels, default is 2
--trim-mode <value> 删除透明像素恢复原始大小,加快渲染 Remove transparent parts of a sprite to shrink atlas size and speed up rendering
None - Keep transparent pixels
Trim - Remove transparent pixels, use original size.
Crop - Remove transparent pixels, use trimmed size, flush position.
CropKeepPos - Remove transparent pixels, use trimmed size, keep position.

--basic-sort-by 图片排序 Sort order for the sprite list
Best - Best
Name - Name
Width - Width
Height - Height
Area - Area
Circumference - Circumference
--basic-order 方向排序 Sorting direction
Ascending - Ascending
Descending - Descending
--scale <float> 缩放 Scales all images before creating the sheet. E.g. use 0.5 for half size
--max-size <int> 最大的尺寸 Sets the maximum width and height for the texture in auto size mode, default is 2048
--size-constraints <value> 结纹理进行大小格式化,AnySize 任何大小 POT 使用2次幂 Restrict sizes
POT - Power of 2 (2,4,8,16,32,...)
AnySize - Minimum size
NPOT - Any size but power of 2

3.知道限定条件,那么命令也大概能知道了

1
2
3
4
5
6
7
8
9
10
11
12
13
Examples:
TexturePacker assets/*.png
creates out.plist and out.png from all png files in assets
trimming all files and creating a texture with max. 2048x2048px

TexturePacker --data main-hd.plist --format cocos2d --sheet main-hd.png assets/*.png
creates main-hd.plist and main-hd.png from all png files in assets
trimming all files and creating a texture with max. 2048x2048px

TexturePacker --scale 0.5 --max-size 1024 --data main-sd.plist --format cocos2d --sheet main-sd.png assets/*.png
creates main-sd.plist and main-sd.png from all png files in assets
scaling all images to 50%, trimming all files and creating
a texture with max. 1024x1024px

4.模板有了之后,剩下的就是实现了

我自己随便写了个脚本,地址 : 地址