当我尝试调试它时,我得到了一个nullpointerexception。 我只是没有得到它,一些东西一定不能正确初始化,但我看不出是什么......谢谢!
@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:没关系,我忘了调用生成纹理的函数....无论如何
答案 0 :(得分:-3)
在public void create()中添加此内容,
renderer.render();