cocos2dx 游戏plist与png完美切成小图python代码
首先需要一份python的切图程序:
#python2.5 unpack_plist.py birdfly #! /usr/lical/bin/python
import os,sys
from xml.etree import ElementTree
from PIL import Image def tree_to_dict(tree):
d = {}
for index, item in enumerate(tree):
if item.tag == 'key':
if tree[index+1].tag == 'string':
d[item.text] = tree[index + 1].text
elif tree[index + 1].tag == 'true':
d[item.text] = True
elif tree[index + 1].tag == 'false':
d[item.text] = False
elif tree[index+1].tag == 'dict':
d[item.text] = tree_to_dict(tree[index+1])
return d def gen_png_from_plist(plist_filename, png_filename):
file_path = plist_filename.replace('.plist', '')
big_image = Image.open(png_filename)
root = ElementTree.fromstring(open(plist_filename, 'r').read())
plist_dict = tree_to_dict(root[0])
to_list = lambda x: x.replace('{','').replace('}','').split(',')
for k,v in plist_dict['frames'].items():
print "-----start\n----------"
rectlist = to_list(v['frame'])
print rectlist, "--------rectlist"
width = int( rectlist[3] if v['rotated'] else rectlist[2] )
height = int( rectlist[2] if v['rotated'] else rectlist[3] )
print width,height,"----width,height"
box=(
int(rectlist[0]),
int(rectlist[1]),
int(rectlist[0]) + width,
int(rectlist[1]) + height,
)
# bos is start & end point
print box,"-----_box-"
print v['rotated'], "---rotated" sizelist = [ int(x) for x in to_list(v['sourceSize'])]
rect_on_big = big_image.crop(box)
'''
result_image = Image.new('RGBA', sizelist, (0,0,0,0))
result_box=(
( sizelist[0] - width )/2,
( sizelist[1] - height )/2,
( sizelist[0] + width )/2,
( sizelist[1] + height )/2
)
result_image.paste(rect_on_big, result_box, mask=0)
if v['rotated']:
result_image = result_image.rotate(90)
if not os.path.isdir(file_path):
os.mkdir(file_path)
outfile = (file_path+'/' + k).replace('gift_', '')
print result_box,"-----result_box-"
print outfile, "generated"
# result_image.save(outfile)
''' if v['rotated']:
# rect_on_big = rect_on_big.rotate(90)
rect_on_big = rect_on_big.transpose(Image.ROTATE_90) # result_image = Image.new('RGBA', sizelist, (0,0,0,0))
# if v['rotated']:
# result_box=(
# ( sizelist[0] - height )/2,
# ( sizelist[1] - width )/2,
# ( sizelist[0] + height )/2,
# ( sizelist[1] + width )/2
# )
# else:
# result_box=(
# ( sizelist[0] - width )/2,
# ( sizelist[1] - height )/2,
# ( sizelist[0] + width )/2,
# ( sizelist[1] + height )/2
# )
# result_image.paste(rect_on_big, result_box, mask=0) if not os.path.isdir(file_path):
os.mkdir(file_path)
outfile = (file_path+'/' + k).replace('gift_', '')
rect_on_big.save(outfile); if __name__ == '__main__':
filename = sys.argv[1]
plist_filename = filename + '.plist'
png_filename = filename + '.png'
if (os.path.exists(plist_filename) and os.path.exists(png_filename)):
gen_png_from_plist( plist_filename, png_filename )
else:
print "make sure you have boith plist and png files in the same directory"
Mac 电脑下可以新建一个文本把程序复制进去,保存后缀名为 .py 并移至与需要切的plist与png文件夹下。
cocos2dx 游戏plist与png完美切成小图python代码的更多相关文章
- Python - 工具:将大图切片成小图,将小图组合成大图
训练keras时遇到了一个问题,就是内存不足,将 .fit 改成 .fit_generator以后还是放不下一张图(我的图片是8192×8192的大图==64M).于是解决方法是将大图切成小图,把小图 ...
- 【Cocos2d-X游戏实战开发】捕鱼达人之开发前准备工作(一)
本系列学习教程使用的是cocos2d-x-2.1.4(最新版为cocos2d-x-2.1.5) 博主发现前两个系列的学习教程被严重抄袭,在这里呼吁大家请尊重开发者的劳动成果, 转载的时候请务必注明出处 ...
- 【Cocos2d-X游戏实战开发】捕鱼达人之单例对象的设计(二)
本系列学习教程使用的是cocos2d-x-2.1.4(最新版为cocos2d-x-2.1.5) 博主发现前两个系列的学习教程被严重抄袭,在这里呼吁大家请尊重开发者的劳动成果, 转载的时候请务必注 ...
- [转]eoe社区cocos2d-x游戏引擎知识大汇总
[eoeAndroid 社区]特意为大家汇总了cocos2d-x知识贴,分量十足,纯正干或.从基础教程到游戏应用的开发,我们不让知识流失,我们要做知识的搬运工还有加工 师.希望大家能够一起的学习,和大 ...
- cocos2d-x 读取.plist文件
转自:http://blog.csdn.net/hgplan/article/details/8629904 在cocos2d-x中可以用.plist格式的文件来保存数据,它是XML文件格式的一种,在 ...
- Cocos2d-x游戏中默认的AndroidManifest.xml的解析
直接上代码说明: <?xml version="1.0" encoding="utf-8"? > <!-- xmlns:android=&qu ...
- Android Cocos2d-x游戏集成友盟社会化组件分享功能
最近在帮助开发者集成友盟社会化组件的过程中,发现游戏的集成过程遇到一些困难,而Cocos2d-x具有较好的代表性,因此整理了一篇关于Android Cocos2d-x游戏集成友盟社会化组件指南,由于本 ...
- 【Cocos2d-x游戏引擎开发笔记(25)】XML解析
原创文章,转载请注明出处:http://blog.csdn.net/zhy_cheng/article/details/9128819 XML是一种非常重要的文件格式,由于C++对XML的支持非常完善 ...
- cocos2d-x 游戏开发之有限状态机(FSM) (二)
cocos2d-x 游戏开发之有限状态机(FSM) (二) 1 状态模式
随机推荐
- iPhone XS 能否经受的起寒冬的考验
我的知乎文章链接: https://zhuanlan.zhihu.com/p/51782644 华北地区近日寒风凛冽,温度骤降,已经进入真正的冬天了,最低温度可以达到零下10度,我们手里的iPhone ...
- php实现简单消息发送+极光推送系统
前几天刚写完的一个东西,写的比较简单,没有使用其他插件,原生php+计划任务实现 极光推送的代码 /* $receiver="registration_id" : [ " ...
- .NET Core开发日志——Dapper与MySQL
Dapper作为.NET生态中广为人知的轻量级ORM类库在.NET Core里仍能被有效利用,并且其不但可以连通SQL Server数据库还提供对其它数据库,比如MySQL的支持.这里试验了一下通过D ...
- process 多进程写法 multiprocessing
from multiprocessing import Process def f1(n):#普通 print(f1) if __name__ == '__main__': lst = [] fo ...
- 依赖: nginx-common (= 1.14.0-0ubuntu1) 但是它将不会被安装
.apt --fix-broken install .sudo apt-get remove nginx nginx-common # 卸载删除除了配置文件以外的所有文件. .sudo apt-get ...
- [No0000168]Excle只允许用户输入纯文本,禁止用户修改单元格样式、格式等
背景:自己的模板给别人,让他填完信息上传到系统里,但别人经常不按模板的格式来填写,导致无法程序自动化.能不能在模板上把格式锁住,只允许输入纯文本,但不能改格式? 方法: 步骤一,创建你要的模板 其中, ...
- layer开启与关闭加载层
// 开启加载层 layer.load(2, { shade: [0.6, '#fff'], content: '数据加载中...', success: function (layero) { lay ...
- 记录一下ionic canvas图片,还有canvas里面的图片跨域的问题
import { Component, Inject, forwardRef } from '@angular/core'; import { IonicPage, NavController, Na ...
- [UI] UI things
反正我不懂. 但是很酷. https://facebook.github.io/react/ https://cn.vuejs.org/ https://angular.cn/
- python 查找函数的用法
python的导入模块:python解释器先检查当前目录下的导入的模块,如果没有找到再检查sys模块中path中的变量(import sys,sys.path),如果没有找到,就会发生错误.可以使用脚 ...