我遇到了libGDX的問題,當我退出後按鈕後恢復應用程序時,我只能看到一個白色屏幕。libGDX按下後退按鈕後的Android白屏
實際的應用程序運行,接受觸摸輸入,並播放聲音,但屏幕只是白色。
我已閱讀,保持對紋理的靜態引用可能會導致此問題,但我不這樣做。
下面是我的資產代碼如何工作的簡化版本。
public class GdxGame extends Game {
private Assets assets;
@Override
public void onCreate() {
assets = new Asstes();
assets.startLoading();
/*
*Within SplashScreen, GdxGame.getAssets() is accessed, and
*manager.update() is called
*/
setScreen(new SplashScreen());
}
@Override
public void dispose() {
assets.dispose();
assets = null;
}
//Perhaps a problem??
public static Assets getAssets() {
return ((GdxGame) Gdx.app.getApplicationListener()).assets;
}
}
public class Assets implements Disposable{
private AssetManager manager;
public Assets() {
manager = new AssetManager();
}
public void startLoading() {
manager.load(....);
}
@Override
public void dispose() {
manager.dispose();
}
}
在後退按鈕之後返回到該應用程序被按下時,AssetManager重新創建時,閃屏被重新打開(如白色),並且AssetManager更新,直到所有的資產被重新加載(約需2秒鐘)。
所以當應用程序重新打開時,新的AssetManager正在加載所有必要的紋理,但由於某些原因,一切仍然是白色的。
它可能與我如何從我的UI和遊戲類訪問AssetManager有關嗎?
//In GdxGame
public Assets getAssets() {
return ((GdxGame) Gdx.app.getApplicationListener()).assets;
}
這是我唯一能看到出錯的地方,但即使如此,我也不明白這可能是什麼問題。
任何幫助將不勝感激。
編輯:
這是SplashScreen類。這使問題更加混亂。在SplashScreen類中,我加載,繪製並處理徽標的新紋理。與AssetManager無關。在按下後退按鈕後返回,這個新的紋理也不會出現。
public class SplashScreen extends Screen {
private Texture logo;
private Assets assets;
@Override
public void show() {
assets = GdxGame.getAssets();
logo = new Texture(Gdx.files.internal("data/logo.png"));
}
@Override
public void render(float delta) {
super.render(float delta);
if(assets.load()) {
//Switch screens
}
//getBatch() is the same form as getAssets() ((GdxGame) Gdx.app.getApplicationListener()).batch)
GdxGame.getBatch().draw(logo, 100, 100, 250, 250);
}
@Override
public void hide() {
super.hide();
logo.dispose();
}
}
如果你向我們展示splashscreen class,那會很好。你不使用暫停和恢復事件嗎? –
@DenizYılmaz我會添加。我使用暫停和恢復事件,但不是任何與資產有關的事情。在這些事件中應該與資產有關嗎?我將添加SplashScreen類。 – grimrader22
你正在討論恢復應用程序,所以我很確定你必須使用簡歷事件。另外你提到你創建新的assetmanager,但是我沒有在任何assetmanager教程中看到。 我想你可以使用 this.assets;而不是 ((GdxGame)Gdx.app.getApplicationListener())。assets; –