我正在尝试将我的主要课程设置为我的gamecreen类。当我尝试运行桌面应用程序时,唯一发生的事情是打开一个黑色背景的窗口并保持半秒然后关闭我不知道为什么它不起作用。我正在使用Netbeans,如果它与它有任何关系。
这是我的主要课程:
public class MyGdxGame extends Game {
public SpriteBatch batch;
@Override
public void create () {
batch = new SpriteBatch();
this.setScreen(new GameScreen(this));
}
@Override
public void render () {
super.render();
}
}
这是我的屏幕类:
public class GameScreen implements Screen{
Texture texture;
private MyGdxGame game;
public GameScreen(MyGdxGame game) {
this.game = game;
texture = new Texture("badlogic.jpg");
}
@Override
public void show() {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void render(float f) {
Gdx.gl.glClearColor(1, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
game.batch.begin();
game.batch.draw(texture, 0, 0);
game.batch.end();
}
//I havn't touched the other methods so I didn't paste them.
我没有触及桌面课程。
我收到此错误消息:
Exception in thread "LWJGL Application" java.lang.UnsupportedOperationException: Not supported yet.
at com.mygdx.game.GameScreen.show(GameScreen.java:27)
at com.badlogic.gdx.Game.setScreen(Game.java:61)
at com.mygdx.game.MyGdxGame.create(MyGdxGame.java:14)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:147)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:124)
答案 0 :(得分:3)
你基本上在方法show()中抛出异常,在将屏幕设置为MyGdxGame类之后立即调用它。
@Override
public void show() {
throw new UnsupportedOperationException("Not supported yet.");
}
从未使用过NetBeans,但看起来它会覆盖带有异常的show()。正如代码中的注释所示,在Tools |中更改生成方法的主体避免此类错误的模板。