Egret切割TextureMerger生成的Sprite Sheet合图文件源码

使用环境

python 2.7.10

TextureMerger 1.7.2

源码地址:https://github.com/smiger/unpacker_texturemerger

1、使用方法

python unpacker.py aa

aa为文件名,如果提示

ImportError: No module named PIL

使用

pip install Pillow

安装即可

2、json格式参考

{
"file":"aa.png",
"frames":{
"0020001":{"x":1,"y":110,"w":60,"h":99,"offX":0,"offY":0,"sourceW":60,"sourceH":99},
"0020002":{"x":438,"y":1,"w":60,"h":99,"offX":0,"offY":0,"sourceW":60,"sourceH":99},
"0020003":{"x":452,"y":102,"w":59,"h":88,"offX":0,"offY":0,"sourceW":59,"sourceH":88},
"0020004":{"x":217,"y":187,"w":68,"h":79,"offX":0,"offY":0,"sourceW":68,"sourceH":79},
"0020005":{"x":287,"y":187,"w":66,"h":80,"offX":0,"offY":0,"sourceW":66,"sourceH":80},
"0020006":{"x":63,"y":186,"w":69,"h":79,"offX":0,"offY":0,"sourceW":69,"sourceH":79},
"0020007":{"x":355,"y":190,"w":59,"h":87,"offX":0,"offY":0,"sourceW":59,"sourceH":87},
"0020008":{"x":416,"y":192,"w":76,"h":66,"offX":0,"offY":0,"sourceW":76,"sourceH":66},
"0020009":{"x":1,"y":267,"w":80,"h":42,"offX":0,"offY":0,"sourceW":80,"sourceH":42},
"0020010":{"x":416,"y":260,"w":79,"h":43,"offX":0,"offY":0,"sourceW":79,"sourceH":43},
"0020011":{"x":156,"y":96,"w":79,"h":82,"offX":0,"offY":0,"sourceW":79,"sourceH":82},
"0020012":{"x":372,"y":106,"w":78,"h":82,"offX":0,"offY":0,"sourceW":78,"sourceH":82},
"0020013":{"x":140,"y":180,"w":75,"h":74,"offX":0,"offY":0,"sourceW":75,"sourceH":74},
"0020014":{"x":63,"y":110,"w":75,"h":74,"offX":0,"offY":0,"sourceW":75,"sourceH":74},
"0020015":{"x":231,"y":1,"w":73,"h":93,"offX":0,"offY":0,"sourceW":73,"sourceH":93},
"0020016":{"x":156,"y":1,"w":73,"h":93,"offX":0,"offY":0,"sourceW":73,"sourceH":93},
"0020017":{"x":1,"y":1,"w":78,"h":107,"offX":0,"offY":0,"sourceW":78,"sourceH":107},
"0020018":{"x":81,"y":1,"w":73,"h":107,"offX":0,"offY":0,"sourceW":73,"sourceH":107},
"0020019":{"x":372,"y":1,"w":64,"h":103,"offX":0,"offY":0,"sourceW":64,"sourceH":103},
"0020020":{"x":306,"y":1,"w":64,"h":104,"offX":0,"offY":0,"sourceW":64,"sourceH":104},
"xue0001":{"x":293,"y":296,"w":72,"h":7,"offX":0,"offY":0,"sourceW":72,"sourceH":7},
"xue0002":{"x":293,"y":279,"w":76,"h":15,"offX":0,"offY":0,"sourceW":76,"sourceH":15},
"xue0003":{"x":215,"y":269,"w":76,"h":35,"offX":0,"offY":0,"sourceW":76,"sourceH":35},
"xue0004":{"x":134,"y":256,"w":79,"h":62,"offX":0,"offY":0,"sourceW":79,"sourceH":62},
"xue0005":{"x":237,"y":107,"w":79,"h":78,"offX":0,"offY":0,"sourceW":79,"sourceH":78}
}
}

3、如果其他TextureMerger版本解析有误,根据json文件相应修改unpacker.py代码中的frames_from_data方法

def frames_from_data(filename, ext):
data_filename = filename + ext
if ext == '.json':
json_data = open(data_filename)
data = json.load(json_data)
frames = {}
for f in data['frames']:
x = int(float(data['frames'][f]["x"]))
y = int(float(data['frames'][f]["y"]))
w = int(float(data['frames'][f]["w"]))
h = int(float(data['frames'][f]["h"]))
real_w = int(float(data['frames'][f]["sourceW"]))
real_h = int(float(data['frames'][f]["sourceH"]))
d = {
'box': (
x,
y,
x + w,
y + h
),
'real_sizelist': [
real_w,
real_h
],
'result_box': (
int((real_w - w) / 2),
int((real_h - h) / 2),
int((real_w + w) / 2),
int((real_h + h) / 2)
),
'rotated': False
}
frames[f] = d
json_data.close()
return frames.items()
else:
print("Wrong data format on parsing: '" + ext + "'!")
exit(1)


发表评论

(必填)

(必填)

(以便回访)

博客已稳定运行: 访问量:156,286 views 网站备案号:闽ICP备17026396号-1