BIG陽(yáng)
2022-01-19 09:24:34
我用坐標(biāo)(x = 100,y = 100,寬度 = 200,高度 = 100)繪制了一個(gè)矩形。然后我圍繞中心轉(zhuǎn)動(dòng)這個(gè)矩形的形狀。this.rotation.addListener((obs, old, fresh) -> { Rotate rotate = new Rotate(); rotate.setAngle((double) fresh - (double) old); rotate.setPivotX(x.getValue().doubleValue() + (width.getValue().doubleValue() / 2)); rotate.setPivotY(y.getValue().doubleValue() + (height.getValue().doubleValue() / 2)); shape.getTransforms().addAll(rotate);});現(xiàn)在如何找出形狀的坐標(biāo)?
1 回答

哆啦的時(shí)光機(jī)
TA貢獻(xiàn)1779條經(jīng)驗(yàn) 獲得超6個(gè)贊
您可以使用該localToParent方法將點(diǎn)從坐標(biāo)系轉(zhuǎn)換Rectangle到父坐標(biāo)系。
Point2D topLeftInParent = shape.localToParent(shape.getX(), shape.getY());
如果您只需要Rectangle顯示 的父級(jí)中的 x/y 范圍,您還可以使用getBoundsInParent:
Bounds parentBounds = shape.getBoundsInParent();
順便說一句:我不建議在每次更改時(shí)添加新的轉(zhuǎn)換。相反,我建議調(diào)整現(xiàn)有的輪換:
Rotate rotate = new Rotate(0, shape.getX() + shape.getWidth()/2, shape.getX() + shape.getHeight()/2);
shape.getTransforms().add(rotate);
rotate.angleProperty().bind(this.rotation);
添加回答
舉報(bào)
0/150
提交
取消