0

我在我的一个项目中使用 Box2DLights。我在这个项目上工作了几个月,我只是尝试将它移植到 Android 上,看看它的外观。虽然桌面版游戏的灯光效果看起来很不错,但在安卓版上看起来真的很难看。灯光渐变一点也不平滑,带有色带效果。以下是桌面版和安卓版的截图: 在此处输入图像描述

为了在我的游戏中使用 Box2DLights,我在 GameScreen 中使用了这段代码:

RayHandler.useDiffuseLight(true); 
rayHandler = new RayHandler(world); 
rayHandler.resizeFBO(Gdx.graphics.getWidth()/5, Gdx.graphics.getHeight()/5); 
rayHandler.setBlur(true);   
rayHandler.setAmbientLight(new Color(0.15f, 0.15f, 0.15f, 0.1f));

我还尝试使用不同的参数,例如:

rayHandler.diffuseBlendFunc.set(GL20.GL_DST_COLOR, GL20.GL_SRC_COLOR);

或者

rayHandler.shadowBlendFunc.set(GL20.GL_DST_COLOR, GL20.GL_SRC_COLOR);

或者

Gdx.gl.glEnable(GL20.GL_DITHER);

我不知道这有帮助,但这里有其他精度:

  • 我的图块集是在 Photoshop 上制作的,并以 RGB 模式记录为 PNG 文件,8 位/通道
  • 在我的 2 台 Android 设备上观察到了这种效果:
    • 平板 Transformer Prime TF701 与 Android 4.2.1
    • 装有 Android 5.0.2 的 LG G Stylo

谢谢你的帮助!

4

1 回答 1

0

这是解决方案:

该问题与 Android 上的低位深度有关。如果您查看AndroidApplicationConfiguration.java的代码,您会在第 30 行和第 31 行注意到这段代码:

/** number of bits per color channel **/
public int r = 5, g = 6, b = 5, a = 0;

因此,带有 libGDX 的 Android 应用程序默认呈现低位图像。这可以在应用程序的AndroidLauncher.java中轻松修改。

您应用的默认 AndroidLauncher.java 如下所示:

public class AndroidLauncher extends AndroidApplication {
    @Override
    protected void onCreate (Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
        initialize(new MyGdxGame(), config);
    }
}

要为您的 Android 应用程序提供 RGBA8888 的渲染格式,您所要做的就是:

public class AndroidLauncher extends AndroidApplication {
    @Override
    protected void onCreate (Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        AndroidApplicationConfiguration config = new AndroidApplicationConfiguration();
        config.r = 8;
        config.g = 8;
        config.b = 8;
        config.a = 8;
        initialize(new MyGdxGame(), config);
    }
}

等等瞧!这是Android RGB565 VS Android RGBA8888 VS Desktop的对比截图: 在此处输入图像描述

可以看到Android RGBA8888与桌面版非常接近。

于 2016-04-03T16:31:10.510 回答