--[[
自动适配(将父级Node对象适配,并将该级所有子类按照原百分比适配)
node : 要适配的父级对象,该对象是要适配
isStretchingChild :是否拉伸子对象拉伸尺寸
]]
function cc.exports.nodeAutoFit(node, isStretchingChild)
local size = cc.size(node:getContentSize().width / CC_DESIGN_RESOLUTION.width * display.width, node:getContentSize().height / CC_DESIGN_RESOLUTION.height * display.height)
local temp = {}
local w = node:getContentSize().width
local h = node:getContentSize().height
for k, v in pairs(node:getChildren()) do
local name = v:getName()
temp[name] = {v:getPositionX()/w, v:getPositionY()/h, v:getContentSize().width, v:getContentSize().height}
end
node:setContentSize(size)
local w = node:getContentSize().width
local h = node:getContentSize().height
local StretchingChild = function(node)
local size = cc.size(node:getContentSize().width / CC_DESIGN_RESOLUTION.width * display.width, node:getContentSize().height / CC_DESIGN_RESOLUTION.height * display.height)
return size
end
for k, v in pairs(node:getChildren()) do
local name = v:getName()
if not isStretchingChild then
v:size(cc.size(temp[name][3], temp[name][4]))
else
v:size(StretchingChild(v))
end
v:setPosition(cc.p(w*temp[name][1], h*temp[name][2]))
end
end