在cocosStudio中创建的node 适配机型

--[[
自动适配(将父级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

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值