我有两个clases,一个用于主要方法,另一个用于飞溅。但是,这两者之间的切换不起作用。我想在Splash类中绘制图像,但它瞬间变黑。当我将代码从splash转移到main类时,图像出现了。在LibGDX中设置新屏幕
主要类:
public class Main extends Game {
public static int WIDTH, HEIGHT;
public void create() {
WIDTH = Gdx.graphics.getWidth();
HEIGHT = Gdx.graphics.getHeight();
setScreen(new Splash());
}
public void render() { }
public void dispose() { super.dispose(); }
public void pause() { super.pause(); }
public void resize(int width, int height) { super.resize(width, height); }
public void resume() { }
}
飞溅类:
public class Splash implements Screen {
private Sprite splash;
private SpriteBatch sb;
public void show() {
sb = new SpriteBatch();
Texture splashTexture = new Texture(Gdx.files.internal("res/img/splash.png"));
splash = new Sprite(splashTexture);
splash.setSize(Main.WIDTH, Main.HEIGHT);
Gdx.gl.glClearColor(0, 0, 0, 1);
}
public void render(float delta) {
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
sb.begin();
splash.draw(sb);
sb.end();
}
public void resize(int width, int height) { }
public void resume() { }
public void dispose() { }
public void hide() { }
public void pause() { }
}
任何想法,什么可能导致飞溅类不渲染图像的问题?
更新1:我发现,那飞溅类中的渲染()方法,甚至不被调用(但show()方法一样)
谢谢你的提示,但我已经想通了。我没有在主类中调用'super.render()'。所以把它放在那里解决了它。 无论如何,你的解决方案似乎也能工作。 – ViliX64