JavaFX 坐标混乱

JavaFX coordinates confusion

我对JavaFX中不同的坐标概念感到很困惑。

据我所知,坐标有3种:

给定一个节点 "node",包含在组 "group" 中,递归地包含在场景 "scene" 中,坐标 "node" 到 "group" 是什么"node" 到 "scene"?我应该使用哪种方法来设置和修改坐标?

还有一个问题,像Polygon这样的对象,在创建多边形的时候需要输入坐标。我应该输入什么坐标?此时的坐标属于哪个层级?

很抱歉问了这个简单的问题,但我花了将近一天的时间搜索 JavaFX 文档,但没有得到任何答案。我需要更多的解释。有没有介绍这些概念的文件?非常感谢!

Node documentation describes the differences. And you should take a look at jewelsea's demo,它对理解 JavaFX 中的布局边界有很大帮助。

多边形是 Shape. You add the coordinates locally, i. e. 0/0 is the coordinate 0/0 inside the Shape. The shape itself can be placed on the scene by using the setLayoutX (and Y) and setTranslateX(和 Y)方法。

这在API docs for the Node class中有解释。基本上:

  • boundsInLocal 是节点在其自身坐标 space 中的边界(在应用缩放和旋转等变换之前)。
  • boundsInParent 是节点在其父级坐标 space 中的边界(并且在应用转换之后)。
  • localToScenelocalToScreen 是可以为您提供场景或屏幕坐标中节点边界的方法 space.