【问题标题】:Why does my LibGdx game black out after a few minutes of playing?为什么我的 LibGdx 游戏在玩了几分钟后就黑屏了?
【发布时间】:2014-01-30 14:13:31
【问题描述】:

好的,在过去一个月的大部分时间里,我一直在制作一款游戏,这确实是一款相当简单的游戏。但是我遇到了一个问题,即我的游戏将“黑屏”,背景完全变黑,fps 从 ~60 直接下降到 0-3 左右,游戏基本上崩溃了。我唯一可能导致这种情况的想法是主要的“级别”类文件的渲染方法。这是 Level.java 文件的代码。如果需要更多信息,我很乐意提供我所能提供的。谢谢。

http://pastebin.com/AfNceFA8 - Level.java

【问题讨论】:

    标签: java graphics libgdx


    【解决方案1】:

    嗯,最大的问题是这样的:

    totalDeathText.setText(deathCount);
    totalDeathText.setPosition(new Vector2(150, 32)); //<-------
    
    levelDeaths.setText(levelDeathCount);
    levelDeaths.setPosition(new Vector2(150, 64)); //<-------
    
    tutText.setText("Press Space to start!");
    tutText.setPosition(new Vector2(250, 432)); //<-------
    LevelText.setText(levelCount + " fps: " + Gdx.graphics.getFramesPerSecond());
    LevelText.setPosition(new Vector2(100, 480)); //<-------
    

    您每帧都在创建新的向量,这缓慢但肯定会导致问题。也不要在每一帧都添加 Inpuprocessor,在 create/constructos 中执行此操作。如果这不能解决问题,那么我们需要更多信息,例如崩溃堆栈跟踪

    【讨论】:

    • 非常感谢!我编辑了代码,并会尽快测试解决方案。如果可行,我会将其标记为正确答案。谢谢!
    • @SketchistGames 您可以使用 myVector = Pools.obtain(Vector2.class) 并在不再需要时调用 Pools.free(myVector) 而不是创建新的 Vecotr2。
    • 或使用.setPosition(float x, float y)
    猜你喜欢
    • 1970-01-01
    • 2018-05-06
    • 1970-01-01
    • 1970-01-01
    • 2022-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多