原因:
1,因再网上扒了一套游戏图,资源都是 .png/plist 的 cocos creator 识别出错
2,在其他地方找了很多,记得有个一款 shoebox 工具导进去就能切割的 找不到了?新的需要安装adobe air 放弃、、
3,网上还有 atlas/plist 的 但是咱的是 png/plist、、、
找了一款python代码 进行分割 for mac
注意事项:
1,mac 自带python 2.7 提示已经放弃维护了 请使用 更高级版本
2,安装后 请使用 pip3 install packageName 执行请使用:python3 test.py 无需切换或者删除自带包
安装包:安装第三方库Pillow,biplist
1)pip3 install biplist
2)pip3 install pillow
执行:python3 test.py
import os
import re
from biplist import readPlist
from PIL import Image
def split_plist_atlas(path):
image = Image.open(os.path.splitext(path)[0]+".png")
plist = readPlist(os.path.splitext(path)[0]+".plist")
prefix = os.path.dirname(path)+os.sep + "Sprites_" + \
get_file_name(path) + os.sep
frames: dict = plist["frames"]
regex = re.compile("({|})")
for k in frames:
filename = prefix + k.replace("jpg", "png")
rectKey = "frame" if "frame" in frames[k] else "textureRect"
rect = regex.sub("", frames[k][rectKey]).split(",")
rect = [int(v) for v in rect]
rotateKey = "rotated" if "rotated" in frames[k] else "textureRotated"
rotate: bool = frames[k][rotateKey]
x = rect[0]
y = rect[1]
w = rect[0] + rect[2] if not rotate else rect[0] + rect[3]
h = rect[1] + rect[3] if not rotate else rect[1] + rect[2]
box = (x, y, w, h)
img = image.crop(box)
if not os.path.exists(prefix):
os.makedirs(prefix)
if rotate:
img = img.rotate(90, expand=1)
img.save(filename)
print(filename)
def get_file_name(path):
filename: str = os.path.split(path)[-1]
index = filename.rfind(".")
return filename[0:index]
while True:
path = input("请将图片资源或plist文件拖到此处:").strip()
print()
if os.path.exists(path):
if os.path.exists(os.path.splitext(path)[0]+".plist"):
try:
split_plist_atlas(path)
print("\nOver\n")
except Exception as e:
print("Exception ", e, "\n")
print("文件解析出错,请重试\n")
else:
print("图片资源或plist文件未找到\n")
else:
print("\n文件路径异常,请重试\n")
代码转:https://blog.csdn.net/qq_23724267/article/details/103186735 谢谢博主 如有侵权望告知