【问题标题】:The game is slower on powerful devices. I am use delta游戏在功能强大的设备上速度较慢。我正在使用三角洲
【发布时间】:2019-06-12 14:54:42
【问题描述】:

为什么 android 游戏在最强大的设备上最慢,但在标准设备上游戏正常,而在劣质设备上游戏速度很快(我的意思是游戏中的移动)。

我尝试将游戏对象速度乘以 delta 并尝试将 FPS 限制为 60f/s。

    @Override
    public void render(float delta) {
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        camera.update();
        stage.act(Math.min(delta, 1 / 61f)); // At now i try with limit
        stage.draw();
        if (!isPaused && isAlive()) {
            if (Gdx.input.getPressure() > 0) balloon.setDir(true);
            else balloon.setDir(false);
            updateLogic(Math.min(delta, 1 / 61f));
        }

/// Its render.

if (getUser().getCurrentLocation().isPaused()) return;
        float tempSpeed = speed * delta;

// Its velocity calculation;

【问题讨论】:

  • “强大”和“标准”是模糊的术语。
  • 将速度乘以增量时间并将其用作游戏速度是没有意义的。将速度乘以增量时间可以得出当前帧的位移量。你用 tempSpeed 做什么?
  • 我是指游戏中的速度对象,它们的移动速度

标签: java libgdx


【解决方案1】:

不同设备上移动速度可变的问题可能是Math.min()引起的。

我们来谈谈三种不同的场景:

  1. 慢速设备:30 FPS/渲染调用,平均。增量 0.033 秒

    Math.min(0.033, 0.016) == 0.016
    
  2. 普通设备:60 FPS/渲染调用,平均。增量 0.017 秒

    Math.min(0.017, 0.016) == 0.016
    
  3. 快速设备:120 FPS/渲染调用,平均。增量 0.008 秒

    Math.min(0.008, 0.016) == 0.008
    

可以看到调用Math.min()后慢速设备上的delta time和普通设备上的一样,导致慢速设备上的速度变慢了。

如果你想限制 FPS,你应该在渲染循环中使用Thread.sleep() 或类似的解决方案,而不是Math.min()。您的解决方案不会限制 FPS,它只会修改更新速度。

This post at libGDX forum 描述了如何限制 FPS 的解决方案。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-03
    相关资源
    最近更新 更多