cocos2d-x 资源优化

一、图片资源优化:

1.使用TexturePacker命令行,把png格式图片的RGBA从8888批量优化为RGBA为4444的pvr.ccz格式图片(此时不会过于失真,且pvr.ccz比png要更优),命令行 png 转pvr4444.bat 代码如下:

@ech off

path %path%;"E:\TexturePacker\bin"

for /f "usebackq tokens=*" %%d in (`dir /s /b *.png`) do (
TexturePacker.exe --opt RGBA4444 --border-padding 0 --disable-rotation --no-trim --allow-free-size --sheet "%%~dpnd.pvr.ccz" "%%d"
)

del out.plist


pause

使用时把bat文件放入png图片资源当前目录,双击怼起。

2.使用pngquant.exe进行优化

此种方法更方便(png转png),更好用(便于指定输入输出目录),更给力(资源在区间内最优,效率最高),推荐使用。

使用方法:

1.)电脑安装lua(解压即可)

2.)在我的电脑-系统属性-环境变量-系统变量-Path中配置lua.exe所在路径D:\InstallZip\Lua\Lua\5.1   切记与前后文用;隔开

3.)在cmd中运行lua,查看lua是否安装成功

3.)修改png_tiny.lua文件,如下:

scan = function(path, tfiletype, tfilename)
path = path or "./"
tfiletype = tfiletype or {"."}
tfilename = tfilename or {}

local need_the_filetype = function(filename)
for k, v in pairs(tfiletype) do
if (string.find(filename, "%" .. v)) then
return true
end
end
return false
end

local cmd = 'dir "'..path..'" /b'
local popen = io.popen(cmd)
for filename in popen:lines() do
if (string.find(filename, "%.")) then
if need_the_filetype(filename) then
tfilename[#tfilename + 1] = {name = filename, path = path}
end
else
scan(path .. filename .. "/", tfiletype, tfilename)
end
end
return tfilename
end

local tiny = function(inpath)
local outpath = string.gsub(inpath, "./input/", "./output/")
os.execute([["pngquant.exe" --force --quality=50-50 ]] .. inpath .. " --output " .. outpath)

end

-----------------------------------------
local pathhead = "./input/"
local tfilename = scan(pathhead, {".png",})
for k, v in pairs(tfilename) do
tiny(v.path..v.name)
print("tiny>" .. 100 * k/#tfilename .. "%")
end

intput 为输入目录,output为输出目录,50-50是优化区间,可取0-100

4.)把pngquant.exe放在png_tiny.lua同级目录,在cmd中用命令行运行lua png_tiny.lua

二、音乐资源优化:

可使用格式转换工厂优化,注意优化效果

三、so文件瘦身

打开cocos2d\cocos\base文件下的ccConfig.h文件,把没有使用的库屏蔽(把#define 的值改为0为不使用,1为使用)


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值