2013-10-19 1 views
2

간단한 애니메이션을 만들어서 화면 주위로 사각형을 이동시키고 원으로 변환하려고합니다.사각형이 JavaFX 2에서 번역되지 않습니다.

모양은 변경되지만 사각형은 변환되지 않습니다. 애니메이션의 KeyFrameKeyValues을 두 번 확인했지만 그럴 수는 없습니다.

SSCCE :

package anim; 

import java.awt.GraphicsDevice; 
import java.awt.GraphicsEnvironment; 

import javafx.animation.KeyFrame; 
import javafx.animation.KeyValue; 
import javafx.animation.Timeline; 
import javafx.animation.TimelineBuilder; 
import javafx.application.Application; 
import javafx.beans.property.DoubleProperty; 
import javafx.beans.property.SimpleDoubleProperty; 
import javafx.geometry.Pos; 
import javafx.scene.Scene; 
import javafx.scene.SceneBuilder; 
import javafx.scene.effect.Reflection; 
import javafx.scene.layout.StackPane; 
import javafx.scene.layout.StackPaneBuilder; 
import javafx.scene.paint.Color; 
import javafx.scene.shape.Rectangle; 
import javafx.scene.shape.RectangleBuilder; 
import javafx.stage.Stage; 
import javafx.stage.StageStyle; 
import javafx.util.Duration; 

public class AroundTheScreen extends Application{ 

    GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); 

    int screenWidth = gd.getDisplayMode().getWidth(); 
    int screenHeight = gd.getDisplayMode().getHeight(); 

    int rectWidth = screenWidth/6; 
    int rectHeight = screenHeight/6; 

    Rectangle rectangle; 
    Timeline animation; 
    Scene theScene; 

    KeyFrame topRight; 
    KeyFrame botRight; 
    KeyFrame botLeft; 
    KeyFrame topLeft; 

    StackPane pane; 

    DoubleProperty movableX = new SimpleDoubleProperty(0.0); 
    DoubleProperty movableY = new SimpleDoubleProperty(0.0); 
    DoubleProperty arcHt = new SimpleDoubleProperty(0.0); 
    DoubleProperty arcWd = new SimpleDoubleProperty(0.0); 

    @Override 
    public void start(Stage stage) throws Exception { 
     pane = StackPaneBuilder 
       .create() 
       .alignment(Pos.TOP_LEFT) 
       .build(); 

     theScene = SceneBuilder 
        .create() 
        .width(screenWidth) 
        .height(screenHeight) 
        .root(pane) 
        .build(); 

     rectangle = RectangleBuilder 
        .create() 
        .width(rectWidth) 
        .height(rectHeight) 
        .fill(Color.rgb(128, 128, 128, 0.5)) 
        .effect(new Reflection()) 
        .build(); 

     rectangle.xProperty().bind(movableX); 
     rectangle.yProperty().bind(movableY); 
     rectangle.arcWidthProperty().bind(arcWd); 
     rectangle.arcHeightProperty().bind(arcHt); 

     topRight = new KeyFrame(new Duration(2000), 
           new KeyValue(arcWd,rectangle.getWidth()), 
           new KeyValue(arcHt,rectangle.getHeight()), 
           new KeyValue(movableX,screenWidth)); 

     botRight = new KeyFrame(new Duration(4000), 
           new KeyValue(arcWd,rectangle.getWidth()), 
           new KeyValue(arcHt,rectangle.getHeight()), 
           new KeyValue(movableY,screenHeight)); 

     botLeft = new KeyFrame(new Duration(6000), 
           new KeyValue(arcWd,rectangle.getWidth()), 
           new KeyValue(arcHt,rectangle.getHeight()), 
           new KeyValue(movableX,screenWidth)); 


     topLeft = new KeyFrame(new Duration(8000), 
        new KeyValue(arcWd,0), 
        new KeyValue(arcHt,0), 
        new KeyValue(movableX, 0), 
        new KeyValue(movableY, 0)); 


     animation = TimelineBuilder 
       .create() 
       .keyFrames(
         topRight, 
         botRight, 
         botLeft, 
         topLeft 
         ) 
       .cycleCount(Timeline.INDEFINITE) 
       .autoReverse(true) 
       .build(); 

     pane.getChildren().add(rectangle); 

     stage.setScene(theScene); 
     stage.sizeToScene(); 
     stage.initStyle(StageStyle.TRANSPARENT); 
     theScene.setFill(Color.TRANSPARENT); 

     stage.show(); 
     animation.play(); 
    } 
    public static void main(String[] args) { 
     Application.launch("anim.AroundTheScreen"); 
    } 
} 

도움말 날 가 자동으로이 창 중심으로 모든 컨텐츠를 재배치 StackPaneTimeline

답변

3

당신은 사각형을 넣어를 사용하여 애니메이션. 따라서 xProperty 개미 yProperty에 대한 모든 수정 사항은 무시됩니다.

대신 Pane을 사용하십시오.