coocs2d-x 分辨率

config.lua:

CC_DESIGN_RESOLUTION = {
  width = 1280,
  height = 720,
autoscale = "FIXED_HEIGHT",
callback = function(framesize)
local ratio = framesize.width / framesize.height
if ratio <= 1.34 then
-- iPad 768*1024(1536*2048) is 4:3 screen
return {autoscale = "FIXED_WIDTH"}
end
end
}

 

 

GameConst.WIN_SIZE = cc.Director:getInstance():getWinSize();

--设计尺寸
GameConst.DESIGN_SIZE = cc.size(1280, 720);

 

 

function CommonUtils.set_node_EXACT_FIT(node_)

-- 假设:屏幕分辨率(fWidth,fHeight) ; 设计分辨率(dWidth,dHeight)。
-- 放缩因子:k1 = fWidth/dWidth ; k2 = fHeight/dHeight。
-- 则适配后的分辨率大小如下:
-- (1)EXACT_FIT :( dWidth * k1 , dHeight * k2 )

local dSize = cc.size(1280, 720);--1280和720是设计尺寸
local winSize = cc.Director:getInstance():getWinSize();
node_:setScale(winSize.width/dSize.width, winSize.height/dSize.height);

 

end

 

 

使用:

--适配--wzq

CommonUtils.set_node_EXACT_FIT(self);
self:setPosition((GameConst.WIN_SIZE.width - GameConst.DESIGN_SIZE.width)/2, (GameConst.WIN_SIZE.height - GameConst.DESIGN_SIZE.height )/2);

 

posted @ 2016-12-02 14:04  黔王  阅读(598)  评论(0编辑  收藏  举报