我正在玩Android Studio中的LIBGDX,我试图在我的游戏中插入图像作为纹理。我正在使用" badlogic.jpg"这包括在例如。 DesktopLauncher和我的Nexus 7上的图像显示正常,但在我的三星Galaxy Note 3上,出现了问题。我希望这些屏幕截图更好地解释:Samsung - Nexus 7
这是我的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();
}
}
和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() {
}
}
这甚至是代码的问题还是我的设备?
答案 0 :(得分:1)
问题在于你已经使你的纹理静态
public static Texture badLogic;
应该是
public Texture badLogic;
Android在应用程序生命周期结束后卸载静态内容存在问题,这就是您看到这些故障的原因
答案 1 :(得分:0)
通过添加Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
到GameRenderer的这一部分:
public void render (float runTime) {
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
batch.draw(badLogic, 0, 0);
batch.end();
}