JavaFX imageview real coordinates translateX and translateY

后端 未结 1 1414
灰色年华
灰色年华 2021-01-17 08:52

And why the translateX and translateY is bad position on my scene ? I start on coordinate x = 100 y = 200 in real my real coordinate y = -24.8 ... why ? I need real coordina

1条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-17 09:17

    I don't know what "real coordinate" means: which coordinate system are you wanting (screen, scene, parent, node...)?

    The value you are displaying is the translateY property; it's the amount by which the node is translated vertically. So -24.8 means it's moved 24.8 units up from its original position.

    You can look at the boundsInParent property, which tells you the bounds of the node in the parent's coordinate system, including any transforms (such as the translation). The boundsInLocal property is the bounds of the node in its own coordinate system, and doesn't include any transforms.

    If you want to get the bounds of the node in scene or screen coordinates, you can use one of the many localToScene(...) or localToScreen(...) methods to convert.

    Update: For example, to track the bounds of the image in scene coordinates, you can do something like:

    ChangeListener listener = new ChangeListener() {
        @Override
        public void changed(ObservableValue ov, Number oldValue, Number newValue) {
            Bounds boundsInScene = iv2.localToScene(iv2.getBoundsInLocal());
            double xInScene = boundsInScene.getMinX();
            double yInScene = boundsInScene.getMinY();
            // do something with values...
        }
    });
    iv2.translateXProperty().addListener(listener);
    iv2.translateYProperty().addListener(listener);
    

    Read the Javadocs for Node for more details.

    0 讨论(0)
提交回复
热议问题