[英]How can I make one Image over another in JavaFX and change it again in an ActionTimer?
我想將圖像“地球”上下移動到圖像“太陽”的前面,以便創建3D效果。
我已經嘗試過使用setBlendMode,但是顯然不適用於圖像。
這是我的代碼:
theStage.setTitle( "Timeline Example" );
Group root = new Group();
Scene theScene = new Scene( root );
theStage.setScene( theScene );
Canvas canvas = new Canvas( 512, 512 );
root.getChildren().add( canvas );
GraphicsContext gc = canvas.getGraphicsContext2D();
Image earth = new Image( "/experiment/img/earth.png" );
Image sun = new Image( "/experiment/img/sun.png" );
Image space = new Image( "/experiment/img/space.png" );
final long startNanoTime = System.nanoTime();
new AnimationTimer()
{
public void handle(long currentNanoTime)
{
double t = (currentNanoTime - startNanoTime) / 1000000000.0;
double x = 232;
double y = 232 + 128 * Math.sin(t);
// background image clears canvas
gc.drawImage( space, 0, 0 );
gc.drawImage( earth, x, y );
gc.drawImage( sun, 196, 196 );
}
}.start();
theStage.show();
}
每當地球落下時,我怎樣才能使地球過太陽?
我一直在尋找函數toBack()和toFront()來實現它們所說的功能。 他們將ImageView或任何其他節點放在背景/前景中。 而且我不再使用畫布了。 我找到了它們,這要歸功於我的Java老師。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.