繁体   English   中英

如何在JavaFX中将一个图像制作成另一个图像,然后在ActionTimer中再次更改它?

[英]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();
    }

每当地球落下时,我怎样才能使地球过太阳?

earth.png

sun.png

space.png

我一直在寻找函数toBack()和toFront()来实现它们所说的功能。 他们将ImageView或任何其他节点放在背景/前景中。 而且我不再使用画布了。 我找到了它们,这要归功于我的Java老师。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM