2015-05-16 17 views
1

当您在旋转的节点上应用DropShadow时,DropShadow随之旋转。有没有简单的方法来保持DropShadow角度,例如, G。即使在节点旋转的时候也是右下角?如何在节点旋转时保持DropShadow的角度

我知道,如果我把所有的节点放到一个组中,并在组上应用阴影,它会工作,但不幸的是这不是我的情况下的选项。

样品图片:

  • 有阴影左矩形
  • 具有相同的阴影权矩形,而是180度

enter image description here

你看旋转,它看起来错误阴影方向相反。

代码

public class HelloEffects extends Application { 

    Stage stage; 
    Scene scene; 

    @Override 
    public void start(Stage stage) { 

     Group group = new Group(); 

     DropShadow ds1 = new DropShadow(); 
     ds1.setOffsetY(4.0f); 
     ds1.setOffsetX(4.0f); 
     ds1.setColor(Color.BLACK); 

     Rectangle rect1 = new Rectangle(100, 200); 
     rect1.relocate(100, 100); 
     rect1.setEffect(ds1); 
     rect1.setFill(Color.RED); 

     Rectangle rect2 = new Rectangle(100, 200); 
     rect2.relocate(300, 100); 
     rect2.setEffect(ds1); 
     rect2.setFill(Color.RED); 
     rect2.setRotate(180); 

     group.getChildren().addAll(rect1, rect2); 

     scene = new Scene(group, 840, 680); 

     stage.setScene(scene); 
     stage.show(); 

    } 

    public static void main(String[] args) { 
     Application.launch(args); 
    } 
} 
+0

我不知道这是可能的,因为应用'Effect'和'Rotation'不会改变相对界限,而是改变界限,所以除非你撤消那个 - 那意味着没有旋转,我的客人将会是你的解决方案。这是我的理解 – Elltz

回答

1

您应该添加一个容器RECT2和应用在容器上的效果,容器可以是面板或组:

Group rect2Container = new Group(rect2); 
rect2Container.setEffect(ds1); 
group.getChildren().addAll(rect1, rect2Container); 
+0

从来没有想过这会很容易。辉煌! –