[英]LIBGDX - Texture glitch
I'm playing around with LIBGDX in Android Studio and I'm trying to insert an image as a texture for my game.我正在 Android Studio 中使用 LIBGDX,并且尝试插入图像作为我游戏的纹理。 I'm using the "badlogic.jpg" that is included for example.例如,我正在使用包含的“badlogic.jpg”。 The image shows up fine on DesktopLauncher and on my Nexus 7 but on my Samsung Galaxy Note 3, something is wrong.该图像在 DesktopLauncher 和我的 Nexus 7 上显示良好,但在我的三星 Galaxy Note 3 上,出现了问题。 I hope these screenshots explain better: Samsung - Nexus 7我希望这些屏幕截图能更好地解释:三星- Nexus 7
This is my GameRenderer class in case that helps:这是我的 GameRenderer 类,以防万一:
public class GameRenderer {
public static Texture badLogic;
private SpriteBatch batch;
private GameWorld myWorld;
private OrthographicCamera cam;
public GameRenderer(GameWorld world) {
myWorld = world;
cam = new OrthographicCamera();
cam.setToOrtho(true, 1920, 1080);
batch = new SpriteBatch();
badLogic = AssetLoader.badLogic;
}
public void render(float runTime) {
batch.begin();
batch.draw(badLogic, 100, 100);
batch.end();
}
}
And GameScreen:和游戏画面:
public class GameScreen implements Screen {
private GameWorld world;
private GameRenderer renderer;
private float runTime;
public GameScreen() {
world = new GameWorld();
renderer = new GameRenderer(world);
}
@Override
public void show() {
}
@Override
public void render(float delta) {
Gdx.app.log("FPS:", (1 / delta) + "");
runTime += delta;
world.update(delta);
renderer.render(runTime);
}
@Override
public void resize(int width, int height) {
}
@Override
public void pause() {
}
@Override
public void resume() {
}
@Override
public void hide() {
}
@Override
public void dispose() {
}
} }
Is this even an issue with the code or is it my device?这甚至是代码的问题还是我的设备?
The problem is that you have made your Texture static问题是您已将纹理设为静态
public static Texture badLogic;
it should be它应该是
public Texture badLogic;
Android has issues with unloading static content after end of application life cycle and that's why you see these glitches Android 在应用程序生命周期结束后卸载静态内容时出现问题,这就是您看到这些故障的原因
Solved by adding Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
通过添加Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
解决Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
to this part in the GameRenderer:到 GameRenderer 中的这部分:
public void render (float runTime) {
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
batch.draw(badLogic, 0, 0);
batch.end();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.