我真的很喜欢这个有趣的问题。我正在做我的装载屏幕。 smallBox将根据资产管理器加载百分比向右移动。当我尝试为我的smallBox设置X()时,我收到了“FATAL EXCEPTION:GLThread 2967”。我试过resize()但没有运气,同样的错误。我不知道我哪里出错了。
这是我的代码:
public class LoadingScreen extends AbstractScreen {
private Image bigBox, smallBox;
private Stage stage;
float loadingPercent=0f;
private SpriteBatch batch;
private Texture loadingTexture;
public LoadingScreen(game game) {
super(game);
// load asset here
Gdx.app.log("gamelog", "assetManager.load()");
game.assetManager.load("img/loading.pack", TextureAtlas.class);
game.assetManager.load("img/splash.pack", TextureAtlas.class);
}
@Override
public void show() {
stage = new Stage();
batch = new SpriteBatch();
loadingTexture = new Texture(Gdx.files.internal("img/loadingTexture.png"));
loadingTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
TextureRegion bigBoxTr = new TextureRegion(loadingTexture, 0, 0, 800, 480);
TextureRegion smallBoxTr = new TextureRegion(loadingTexture, 0, 790, 800, 110);
Image bigBox = new Image(bigBoxTr);
Image smallBox = new Image(smallBoxTr);
smallBox.setX(-800);
smallBox.setY(160);
bigBox.setX(0);
bigBox.setY(0);
stage.addActor(bigBox);
stage.addActor(smallBox);
}
@Override
public void render(float delta) {
// Clear the screen
Gdx.gl.glClearColor(0f, 0f, 0f, 1f);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
loadingPercent = Interpolation.linear.apply(loadingPercent, game.assetManager.getProgress(), 0.1f);
Gdx.app.log("gamelog", "LoadingScreen: =" + (-800+(int)(loadingPercent*800*2)) + " getProgress" + game.assetManager.getProgress());
smallBox.setX(-800+(int)(loadingPercent*800*2)); //<------ problem point
smallBox.invalidate();
if (game.assetManager.update()) {
Gdx.app.log("gamelog", "LoadingScreen: before calling SplashScreen =" + (-800+(int)(loadingPercent*800*2)) + " getProgress" + game.assetManager.getProgress());
game.setScreen(new SplashScreen(game));
}
stage.act(delta);
stage.draw();
}
错误登录LogCat
11-01 22:08:54.308: I/awesomegame(24701): LoadingScreen: =-800 getProgress0.0
11-01 22:08:54.318: D/memalloc(24701): /dev/pmem: Unmapping buffer base:0x51f68000 size:10297344 offset:9527296
11-01 22:08:54.328: W/dalvikvm(24701): threadid=11: thread exiting with uncaught exception (group=0x40c2ca68)
11-01 22:08:54.328: E/AndroidRuntime(24701): FATAL EXCEPTION: GLThread 2967
11-01 22:08:54.328: E/AndroidRuntime(24701): java.lang.NullPointerException
11-01 22:08:54.328: E/AndroidRuntime(24701): at com.example.awesomegame.screens.LoadingScreen.render(LoadingScreen.java:128)
11-01 22:08:54.328: E/AndroidRuntime(24701): at com.badlogic.gdx.Game.render(Game.java:46)
11-01 22:08:54.328: E/AndroidRuntime(24701): at com.example.awesomegame.somegame.render(somegame.java:25)
11-01 22:08:54.328: E/AndroidRuntime(24701): at com.badlogic.gdx.backends.android.AndroidGraphics.onDrawFrame(AndroidGraphics.java:487)
11-01 22:08:54.328: E/AndroidRuntime(24701): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1463)
11-01 22:08:54.328: E/AndroidRuntime(24701): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1217)
然而,当我注释掉行“smallBox.setX(-800+(int)(loadingPercent * 800 * 2)); //&lt; ------ problem point”时,bigBox正确显示。我认为是float / int问题,但根据LogCat(当行注释掉时):
11-01 22:03:29.261: I/awesomegame(24283): LoadingScreen: =-800 getProgress0.0
11-01 22:03:29.301: D/memalloc(24283): /dev/pmem: Mapped buffer base:0x52e94000 size:4255744 offset:3485696 fd:67
11-01 22:03:29.301: I/awesomegame(24283): LoadingScreen: =-800 getProgress0.0
11-01 22:03:29.311: D/memalloc(24283): /dev/pmem: Mapped buffer base:0x533c7000 size:5025792 offset:4255744 fd:70
11-01 22:03:29.321: I/awesomegame(24283): LoadingScreen: =-800 getProgress0.0
11-01 22:03:29.331: I/awesomegame(24283): LoadingScreen: =-800 getProgress0.0
...
11-01 22:03:30.362: I/awesomegame(24283): LoadingScreen: =-38 getProgress0.5
11-01 22:03:30.512: I/awesomegame(24283): LoadingScreen: =-34 getProgress0.5
11-01 22:03:30.532: I/awesomegame(24283): LoadingScreen: =-31 getProgress0.5
11-01 22:03:30.532: I/awesomegame(24283): LoadingScreen: =-28 getProgress0.5
11-01 22:03:30.552: I/awesomegame(24283): LoadingScreen: =-25 getProgress0.5
11-01 22:03:30.572: I/awesomegame(24283): LoadingScreen: =-23 getProgress0.5
11-01 22:03:30.572: I/awesomegame(24283): LoadingScreen: =-21 getProgress0.5
11-01 22:03:30.592: I/awesomegame(24283): LoadingScreen: =-19 getProgress0.5
11-01 22:03:30.612: I/awesomegame(24283): LoadingScreen: =-17 getProgress0.5
11-01 22:03:30.612: I/awesomegame(24283): LoadingScreen: =-15 getProgress0.5
11-01 22:03:30.672: I/awesomegame(24283): LoadingScreen: =-14 getProgress0.5
11-01 22:03:30.692: I/awesomegame(24283): LoadingScreen: =-12 getProgress0.5
11-01 22:03:30.872: I/awesomegame(24283): LoadingScreen: =-11 getProgress0.5
11-01 22:03:30.882: I/awesomegame(24283): LoadingScreen: before calling SplashScreen =-11 getProgress1.0
似乎工作方式是正确的。我已经坚持这个问题好几天了,不知道在哪里以及如何解决它。
非常感谢,非常感谢任何帮助。
此致 籽亿
答案 0 :(得分:0)
我发现了问题的来源。在跟踪每个步骤之后,似乎小盒子被放置在LoadingScreen和AbstractScreen之间。解决方案是添加“这个”。作为小盒子的前缀。
无论如何,无论如何,谢谢你的帮助,@ noone