用户:
冷鱼闲风查看: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 });
}
神岛吉吉喵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
评论