【问题标题】:Low fps on LibGDXLibGDX 上的低 fps
【发布时间】:2017-06-14 19:02:02
【问题描述】:

如果没有此代码,fps 为 60-65。但是当我使用这段代码时,fps 下降到 50。

另一个问题是某些设备上的 FPS 太低。但是,游戏非常简单。我将 ShapeRenderer 用于所有形状。游戏在这里:link

    try {
            Thread.sleep((long)(1000/60-Gdx.graphics.getDeltaTime()));
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

编辑:我用这段代码解决了这个问题 --> link.

【问题讨论】:

  • 你不应该使用那个代码,你想限制 fps 吗?
  • 你为什么要把它转换成 long ?此除法将被视为具有完整整数结果的整数除法,而是转换为浮点类型。
  • 请...不要将所有内容都写入 try&catch 块中。
  • @HannesHauptmann 那么,我应该使用什么代码来限制 fps
  • 谷歌搜索“交换间隔 opengl”

标签: java libgdx


【解决方案1】:

您可以通过在应用加载程序的配置中定义 foregroundFPS 来将 FPS 限制为您希望在 libgdx 应用程序中使用的任何值。

LwjglApplicationConfiguration config = new LwjglApplicationConfiguration();
    config.width = 640;
    config.height = 480;
    config.foregroundFPS = 60; // <- limit when focused
    config.backgroundFPS = 60; // <- limit when minimized
    config.samples =2; // AA for shape renderer.. not textures!
    new LwjglApplication(new libgdxapp(), config);

android config

Continuous rendering

【讨论】:

  • 好吧,我在 android 上做什么。而cfg.samples = 2 不适用于 AA。
  • 在 android 中你使用 config.numSamples = 2 而不是 samples
  • 我的意思是 cfg.samples 不能在桌面上工作。还有,Android 的config.foregroundFPS = 60 代码是什么
  • 我的回答 foregroundFPS 中的链接将带您进入桌面版本的配置选项。我也将 android 版本添加到我的答案中。它没有 foregroundFPS 选项,但如果您必须限制 FPS,您可以通过禁用连续渲染来手动执行此操作,我也已将其添加到我的答案中。
猜你喜欢
  • 1970-01-01
  • 2015-01-14
  • 1970-01-01
  • 1970-01-01
  • 2022-08-03
  • 1970-01-01
  • 2021-06-17
  • 2012-08-08
  • 2023-03-21
相关资源
最近更新 更多