回答
floaty.window() 创建的悬浮窗对象没有 bounds() 方法,需要用其他方式获取位置。
正确获取悬浮窗位置
// 文档地址 https://docs.hamibot.com/
// 创建悬浮窗
var w = floaty.window(
<frame bg="#AA000000">
<text id="txt">测试</text>
</frame>
);
// 获取位置(正确方式)
var x = w.getX(); // 获取 X 坐标
var y = w.getY(); // 获取 Y 坐标
log("悬浮窗位置: " + x + ", " + y);
// 设置位置
w.setPosition(100,200);
// 获取宽高
var width = w.getWidth();
var height = w.getHeight();
log("悬浮窗大小: " + width + "x" + height);
如果需要 bounds 格式
// 文档地址 https://docs.hamibot.com/
var x = w.getX();
var y = w.getY();
var width = w.getWidth();
var height = w.getHeight();
// 模拟 bounds 对象
var bounds = {
left: x,
top: y,
right: x + width,
bottom: y + height,
centerX: function() { return this.left + this.width / 2; },
centerY: function() { return this.top + this.height / 2; },
width: width,
height: height
};
log("left: " + bounds.left);
log("top: " + bounds.top);
log("centerX: " + bounds.centerX());
log("centerY: " + bounds.centerY());
常见错误对比
| 错误写法 | 正确写法 |
|---|---|
w.bounds() |
w.getX(), w.getY() |
w.width |
w.getWidth() |
w.height |
w.getHeight() |
注意:floaty.window() 和 floaty.rawWindow() 返回的对象使用 getX() / getY() / getWidth() / getHeight() 方法,而 UiObject(如 text().findOne())才使用 bounds() 方法。
ℹ️ 内容由 AI 生成,可能不准确,请注意核实