使用localToScene(x,y)获取节点的场景中的位置会返回错误的值 [英] Getting position in Scene of a Node with localToScene(x,y) returns wrong value

查看:148
本文介绍了使用localToScene(x,y)获取节点的场景中的位置会返回错误的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将弹出的窗格的位置绑定到调用它的Button的位置,我尝试通过调用 button.localToScene(button.getLayoutX(),button.getLayoutY)来实现这一点。 ()。但是返回的Point2D变量中有一个错误的X坐标。我在Gimp测量它,它应该是320但是它返回586。

I want to bind the position of a pane that pops up to the position of the Button calling it, and I tried doing so by callling button.localToScene(button.getLayoutX(),button.getLayoutY(). However the returned Point2D variable has the wrong X coordinate in it. I measured it in Gimp and its supposed to be at 320 but it returns me 586.

localToScreen()相同的故事顺便说一下,在按钮已经出现之前我甚至没有586像素的屏幕区域,所以它不可能是在该坐标处。

Same story with localToScreen() btw, I dont even have 586 pixels of screen estate until the button already shows up, so its impossible for it to be at that coordinate.

推荐答案

您可能希望获得与包含按钮的元素相关的按钮的节点位置,例如窗格或者场景,如果你提供它会有帮助的代码。但是这样的地方,你得到包含你的按钮的窗格的位置,然后得到你的按钮位置并解决差异。但我建议尝试这个:

You may want to get the button's node position relevant to the element that contains the button such as a pane or the scene, if you provide code it would help. But something like this where you get the location of the pane that contains your button, then get ur button position and work out the difference. But i suggest trying this:

Bounds boundsInScene = button.localToScene(button.getBoundsInLocal());

或者这相对于屏幕:

Bounds boundsInScreen = button.localToScreen(button.getBoundsInLocal());

然后使用方法:getMinX(),getMinY(),getMaxX(),getMaxY(), getWidth()或getHeight()来获取实际按钮的值。

Then use the methods : getMinX(), getMinY(), getMaxX(), getMaxY(), getWidth() or getHeight() to get the values of your actual button.

希望这会有所帮助。

这篇关于使用localToScene(x,y)获取节点的场景中的位置会返回错误的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆