猫史档案馆


【Box3函数分享】GameUI元素根据玩家窗口计算居中操作

用户:冷鱼闲风冷鱼闲风查看:2 回复:7 评论:2 创建时间:2024-01-24T14:41:57



/**
 * @function  autoWidthAndHeight
 * @param {string} type 自动宽高方式:w:只宽度居中,h:只高度居中,wh:宽度高度居中
 * @param {UiNode} ui ui节点,一般使用根节点。
 * @param {number} x_offset x方向[宽度]偏移位置,填写0-1之间的小数。
 * @param {number} y_offset y方向[高度]偏移位置,填写0-1之间的小数。
 * @desc UI元素根据玩家屏幕分辨率自动宽高居中操作。
 */
function autoWidthAndHeight(type, ui, x_offset = 1, y_offset = 1) {
    ui.position.offset.copy({ x: type.toLowerCase() == 'w' || type.toLowerCase() == 'wh' ? (screenWidth * 0.5 - (ui.size.offset.x / 2)) * x_offset : (screenWidth - ui.size.offset.x) * x_offset, y: type.toLowerCase() == 'h' || type.toLowerCase() == 'wh' ? (screenHeight * 0.5 - (ui.size.offset.y / 2)) * y_offset : (screenHeight - ui.size.offset.y) * y_offset });
}


回复

上一页1 页 / 共 1下一页
北京_地铁迷北京_地铁迷

沙发

点赞1


评论


神岛皮皮喵神岛皮皮喵

板凳

点赞0


评论


神岛吉吉喵神岛吉吉喵

imgsr喵demao.cn/emoji/codemao/%E7%BC%96%E7%A8%8B%E7%8C%AB_%E5%8E%89%E5%AE%B3%E4%BA%86.gif"alt="emotion_编程猫_厉害了"

点赞0


评论


yee剑走天下yee剑走天下

能解释一下原理吗谢谢emotion_doge

点赞0


评论


145a145a

nb!!

点赞0


评论


传说之下ULB--sans传说之下ULB--sans

板凳

 

 

点赞0


评论


Star_Ink_sansStar_Ink_sans

看到是鱼鱼发的就进来了(喜)

顺便顶一下()

点赞1


评论