我正在尝试在屏幕上绘制 .png,但我不断收到错误消息。我正在使用的类是 Screen 的子类。
这是我得到的错误:
FATAL EXCEPTION GLThread 1335 java.lang.NullPointerException at SplashScreen.java.32
这一行是:
batch.begin()
这是我在 Screen 子类中的代码:
private SpriteBatch batch;
private Texture splashTexture;
private Camera camera;
final int CAMERA_WIDTH = Gdx.graphics.getWidth();
static final int CAMERA_HEIGHT = Gdx.graphics.getHeight();
@Override
public void render(float delta) {
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
batch.begin();
batch.draw(splashTexture, 0, 0);
batch.end();
}
@Override
public void resize(int width, int height) {
// TODO Auto-generated method stub
}
@Override
public void show() {
splashTexture = new Texture(Gdx.files.internal("splash.png"));
camera = new OrthographicCamera(CAMERA_WIDTH, CAMERA_HEIGHT);
camera.position.set(CAMERA_WIDTH, CAMERA_HEIGHT, 0);
}