当我尝试调试它时,我得到了一个空指针异常。我只是不明白,某些东西必须没有正确初始化,但我看不到什么......谢谢!
@Override
public void create()
{
Texture.setEnforcePotImages(false);
camera = new OrthographicCamera(VIRTUAL_WIDTH, VIRTUAL_HEIGHT);
camera.setToOrtho(true,VIRTUAL_WIDTH,VIRTUAL_HEIGHT);
batch = new SpriteBatch();
labyrinthe = new Labyrinthe(2, VIRTUAL_WIDTH);
labyrinthe.generer();
joueur = labyrinthe.getJoueur();
}
@Override
public void dispose()
{
batch.dispose();
}
@Override
public void render()
{
camera.position.set(joueur.getX(), joueur.getY(), 0);
camera.update();
camera.apply(Gdx.gl10);
Gdx.gl.glViewport((int) viewport.x, (int) viewport.y, (int) viewport.width, (int) viewport.height);
Gdx.gl.glClearColor(1, 1, 1, 1);
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
batch.setProjectionMatrix(camera.combined);
batch.begin();
dessinerLabyrinthe();
dessinerJoueur();
batch.end(); // Exception on this line
}
编辑:这是例外:
08-24 09:22:02.413: W/dalvikvm(224): threadid=21: thread exiting with uncaught exception (group=0x4001b188)
08-24 09:22:02.413: E/AndroidRuntime(224): Uncaught handler: thread GLThread exiting due to uncaught exception
08-24 09:22:02.480: E/AndroidRuntime(224): java.lang.NullPointerException
08-24 09:22:02.480: E/AndroidRuntime(224): at com.badlogic.gdx.graphics.g2d.SpriteBatch.renderMesh(SpriteBatch.java:1042)
08-24 09:22:02.480: E/AndroidRuntime(224): at com.badlogic.gdx.graphics.g2d.SpriteBatch.end(SpriteBatch.java:269)
08-24 09:22:02.480: E/AndroidRuntime(224): at com.me.crazymazes.CrazyMazes.render(CrazyMazes.java:60)
08-24 09:22:02.480: E/AndroidRuntime(224): at com.badlogic.gdx.backends.android.AndroidGraphics.onDrawFrame(AndroidGraphics.java:452)
08-24 09:22:02.480: E/AndroidRuntime(224): at com.badlogic.gdx.backends.android.surfaceview.GLSurfaceViewCupcake$GLThread.guardedRun(GLSurfaceViewCupcake.java:713)
08-24 09:22:02.480: E/AndroidRuntime(224): at com.badlogic.gdx.backends.android.surfaceview.GLSurfaceViewCupcake$GLThread.run(GLSurfaceViewCupcake.java:646)
Edit2:没关系我忘了调用生成纹理的函数....还是谢谢