翻译不顺利

时间:2015-05-09 13:39:09

标签: javafx timeline smooth

我使用TranslateTransitionImageView从中移出到舞台窗口的中心。这是问题:动画跳跃。 ImageView的运动不是平滑和线性的。我尝试启用-Dcom.sun.scenario.animation.vsync=true, -Dcom.sun.scenario.animation.adaptivepulse=true属性,但没有成功。认为这些问题可能是由于PC的功能,我运行应用程序更强大和不同的PC(I7与16GB的RAM),但再次没有成功,动画不顺利。 我读到JavaFX定时器根据屏幕hz自动计算脉冲。 那么你可以帮我解决动画不顺畅的原因吗?

MVCE:

import java.io.File;

import javafx.animation.Animation;
import javafx.animation.Interpolator;
import javafx.animation.PauseTransition;
import javafx.animation.SequentialTransition;
import javafx.animation.TranslateTransition;
import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
import javafx.util.Duration;

public class MCVE extends Application
{
    private Stage   stage;
    private String  title   = null;

    public static void main(String[] args)
    {
        Application.launch(MCVE.class, new java.lang.String[] { "--filename=./template.fxml" });
    }

    public MCVE()
    {
    }

    @Override
    public void start(Stage primaryStage) throws Exception
    {
        stage = primaryStage;

        final Parameters params = getParameters();

        // load fxml
        final AnchorPane page = (AnchorPane) FXMLLoader.load(new File(params.getNamed().get("filename")).toURI().toURL());
        Scene scene = new Scene(page);

        // setup stage
        stage.setScene(scene);
        stage.setMinWidth(page.getPrefWidth());
        stage.setMinHeight(page.getPrefHeight());
        stage.setWidth(page.getPrefWidth());
        stage.setHeight(page.getPrefHeight());

        stage.setTitle(title);

        // setup full screen mode
        EventHandler<MouseEvent> mouseHandler = new EventHandler<MouseEvent>()
        {
            @Override
            public void handle(MouseEvent mouseEvent)
            {
                if (mouseEvent.getClickCount() >= 2)
                {
                    stage.setFullScreen(!stage.isFullScreen());
                }
            }
        };
        scene.setOnMouseClicked(mouseHandler);

        // setup scene
        setupScene();

        // open the stage
        stage.show();
    }

    /**
     * @param nodeName
     * @return
     */
    private Node getNode(String nodeName)
    {
        return stage.getScene().lookup("#" + nodeName.toLowerCase());
    }

    /**
     * 
     */
    private void setupScene()
    {
        String userdir = System.getProperty("user.dir");

        // slide node
        final Node node = getNode("image");

        long inTime = 5000;
        long pauseTime = 3000;
        long outTime = 5000;

        TranslateTransition in = new TranslateTransition(Duration.millis(inTime));
        in.setFromX(-1280);
        in.setToX(node.translateXProperty().getValue());
        in.setInterpolator(Interpolator.EASE_IN);

        PauseTransition pause = new PauseTransition(Duration.millis(pauseTime));

        TranslateTransition out = new TranslateTransition(Duration.millis(outTime));
        out.setFromX(node.translateXProperty().getValue());
        out.setInterpolator(Interpolator.EASE_OUT);
        out.setToX(1280 + node.getBoundsInLocal().getWidth());

        final SequentialTransition  timeline = new SequentialTransition(node, in, pause, out);
        timeline.setCycleCount(Animation.INDEFINITE);
        timeline.play();

    }

}

Here下载所需的资源。 将它们保存到工作文件夹中。

这是带有-Dprism.verbose = true的转储

Prism pipeline init order: d3d sw
Using platform text rasterizer
Using native-based Pisces rasterizer
Using dirty region optimizations
Not using texture mask for primitives
Not forcing power of 2 sizes for textures
Using hardware CLAMP_TO_ZERO mode
Opting in for HiDPI pixel scaling
Prism pipeline name = com.sun.prism.d3d.D3DPipeline
Loading D3D native library ...succeeded.
D3DPipelineManager: Created D3D9Ex device
Direct3D initialization succeeded
(X) Got class = class com.sun.prism.d3d.D3DPipeline
Initialized prism pipeline: com.sun.prism.d3d.D3DPipeline
OS Information:
Windows 7 build 7601
D3D Driver Information:
ATI Mobility Radeon HD 4650
\\.\DISPLAY1
Maximum supported texture size: 8192
Maximum texture size clamped to 4096
Driver atiumd64.dll, version 8.14.10.678
Pixel Shader version 3.0
Device : ven_1002, dev_9480, subsys_02051025
Max Multisamples supported: 4

干杯, 法比奥

1 个答案:

答案 0 :(得分:1)

尝试在节点(图片)上设置缓存 cacheHint 以获得流畅的动画效果,即

 node.setCache(true);
 node.setCacheHint(CacheHint.SPEED);

检查JavaFX 8 Node以获取更多信息