我有一个启动类,它应该只显示启动图像,但它会导致空指针异常。当我在其他 Java 应用程序中使用这种方法时,它很激动。我已经阅读了大量文档以了解我哪里出错了,但我似乎找不到它。
Splash.java class
package com.me.fypapplication;
import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
public class Splash implements Screen{
private SpriteBatch spriteBatch;
private Texture splashTexture;
private Sprite sprite;
private Game myGame;
private OrthographicCamera camera;
public Splash (Game g)
{
myGame = g;
}
public void create() {
camera = new OrthographicCamera(800,400);
splashTexture = new Texture(Gdx.files.internal("data/splashtest.gif"));
sprite = new Sprite(splashTexture);
sprite.setSize(512, 512);
sprite.setPosition(256, 256);
spriteBatch = new SpriteBatch();
splashTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
}
@Override
public void render(float delta) {
Gdx.gl.glClearColor(0.1f, 0.1f, 0.1f, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
camera.update();
spriteBatch.begin();
sprite.draw(spriteBatch);
spriteBatch.end();
}
如果有人可以提供帮助将不胜感激!
编辑!忘记了错误
Exception in thread "LWJGL Application" java.lang.NullPointerException
at com.me.fypapplication.Splash.render(Splash.java:51)
at com.badlogic.gdx.Game.render(Game.java:46)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:190)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:110)