【发布时间】:2019-02-24 22:17:07
【问题描述】:
我正在用 Gluon 开发一个应用程序。目前,它只是一个简单的立方体。
我正在使用 AnimationTimer 来处理游戏循环。当动画计时器是句柄时,我比较系统的纳秒来计算帧增量时间。我通过以下方式显示 fps:1/DeltaTime。
在桌面上,fpsLabel 显示恒定的 60 fps。但是,在移动设备上,我只能收到 30 fps。我注意到控制台有时会写入 setSwapInterval(1),我知道这是 OpenGL 中的 VSYNC 设置。我的手机真的没有达到 60 fps 的目标并被限制吗?使用 Gluon 获得更直接的 OpenGLES 支持可能会有所帮助。
// Content pane
StackPane content = new StackPane();
content.setAlignment(Pos.TOP_LEFT);
content.setPadding(new Insets(8));
content.setPrefSize(Integer.MAX_VALUE, Integer.MAX_VALUE);
this.setCenter(content);
// Holds 3d objects
Group root3D = new Group();
// Scene to view the 3d objects
SubScene subScene = new SubScene(root3D, MobileApplication.getInstance().getScreenWidth(), MobileApplication.getInstance().getScreenHeight(), true, SceneAntialiasing.DISABLED);
content.getChildren().add(subScene);
// Create camera
PerspectiveCamera camera = new PerspectiveCamera(true);
camera.setNearClip(0.1);
camera.setFarClip(1000.0);
camera.setTranslateZ(-64);
root3D.getChildren().add(camera);
// Put camera in scene
Platform.runLater(()->{
subScene.setCamera(camera);
subScene.widthProperty().bind(MobileApplication.getInstance().getView().widthProperty());
subScene.heightProperty().bind(MobileApplication.getInstance().getView().heightProperty());
});
// Put box in scene
Box box = new Box(8, 8, 8);
Rotate rxBox = new Rotate(0, 0, 0, 0, Rotate.X_AXIS);
boxRot = new Rotate(0, 0, 0, 0, Rotate.Y_AXIS);
rxBox.setAngle(30);
boxRot.setAngle(50);
box.getTransforms().addAll(rxBox, boxRot);
root3D.getChildren().add(box);
// FPS Label
fpsLabel = new Label("Fps 60");
content.getChildren().add(fpsLabel);
【问题讨论】:
标签: javafx gluon gluon-mobile