你應該考慮根據你的需要加載你的遊戲資產,你應該管理你的資產真的很好。在遊戲中加載和卸載資產。這將有助於防止低迴憶造成的痛苦崩潰。使用類似這樣的東西作爲屏幕的入口點,以防使用更簡單的舞臺。
public class LoadingScreen extends MyAbstractScreen {
private static final String TAG = "ASSETLOAD";
public static final int TYPE_UI_MENU = 0;
public static final int TYPE_UI_LEVEL = 1;
public static final int TYPE_UI_HIGHSCORE = 2;
public static final int TYPE_UI_CREDIT = 3;
public static final int TYPE_UI_INSTRUCTION = 4;
public static final int TYPE_GAME = 5;
public static final String BASE_ATLAS ="data/base/base_atlas.pack";
public static final String UI_MENU_ATLAS ="data/ui_menu/menu_atlas.pack";
public static final String UI_LEVEL_ATLAS ="data/ui_level/level_atlas.pack";
public static final String UI_HIGHSCORE_ATLAS ="data/ui_highscore/highscore_atlas.pack";
public static final String UI_CREDIT_ATLAS ="data/ui_credit/credit_atlas.pack";
public static final String UI_INSTRUCTION ="data/ui_instruction/instruction_atlas.pack";
public static final String GAME_ATLAS ="data/game_screen/game_atlas.pack";
private int type;
private Texture background_loading, logo, progressBarImg, progressBarBaseImg;
private SpriteBatch batch;
private boolean loaded = false;
private Vector2 logoPos, pbPos;
public TableModel menuTable;
public EmptyActorLight btnLogo;
public LoadingScreen(Game game, String screenName, int type)
{
super(game, screenName);
this.type = type;
}
@Override
public void show()
{
batch = new SpriteBatch();
// Load assets needed for loading screen
getMyGame().getManager().loadGroup("loading_screen");
getMyGame().getManager().loadGroup("base");
getMyGame().getManager().finishLoading(); //Blocks until all resources are loaded into memory
Gdx.app.log(TAG, "Assets loaded");
// Get Assets
background_loading = getMyGame().getManager().get("data/loading_screen/background_loading.png");
logo = getMyGame().getManager().get("data/loading_screen/logo.png");
//progressBarImg = getMyGame().getManager().get("data/loading_screen/progress_bar.png");
//progressBarBaseImg = getMyGame().getManager().get("data/loading_screen/progress_bar_base.png");
// Get logo position
//logoPos = new Vector2();
// Centre the log in the screen
//logoPos.set(Gdx.graphics.getWidth()/2 - logo.getWidth()/2, Gdx.graphics.getHeight()/2 - logo.getHeight()/2);
// ProgressBar position
//pbPos = new Vector2();
//pbPos.set(logoPos.x, logoPos.y - (logo.getHeight()));
//Depending on screen type load appropriate assets
switch (type)
{
case TYPE_UI_MENU:
if(getMyGame().getManager().isLoaded(GAME_ATLAS, TextureAtlas.class))
{
getMyGame().getManager().unloadGroup("game_screen");
}
getMyGame().getManager().loadGroup("ui_menu");
break;
case TYPE_UI_LEVEL:
getMyGame().getManager().loadGroup("ui_level");
break;
case TYPE_UI_HIGHSCORE:
getMyGame().getManager().loadGroup("ui_highscore");
break;
case TYPE_UI_CREDIT:
getMyGame().getManager().loadGroup("ui_credit");
break;
case TYPE_UI_INSTRUCTION:
getMyGame().getManager().loadGroup("ui_instruction");
break;
case TYPE_GAME:
getMyGame().getManager().unloadGroup("ui_menu");
getMyGame().getManager().unloadGroup("ui_level");
getMyGame().getManager().unloadGroup("ui_instruction");
getMyGame().getManager().loadGroup("ui_game");
break;
}
}
@Override
public void render(float delta)
{
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
//Render background image
//batch.begin();
//batch.draw(background_loading, 0, 0);
//batch.end();
// Check if async load is done
if (!loaded)
{
// Render Logo and Loading Bar
batch.begin();
batch.draw(logo, Gdx.graphics.getWidth()/2 - logo.getWidth()/2, Gdx.graphics.getHeight()/2 - logo.getHeight()/2);
//batch.draw(progressBarBaseImg, pbPos.x, pbPos.y);
//batch.draw(progressBarImg, pbPos.x, pbPos.y,progressBarImg.getWidth() * getMyGame().getManager().getProgress(),progressBarImg.getHeight());
batch.end();
if (getMyGame().getManager().update())
{
loaded = true;
switch (type)
{
case TYPE_UI_MENU:
((Game) Gdx.app.getApplicationListener()).setScreen(new MenuScreen(getMyGame(), "MainMenu Screen"));
break;
case TYPE_UI_LEVEL:
((Game) Gdx.app.getApplicationListener()).setScreen(new LevelSelectScreen(getMyGame(),"LevelSelect Screen"));
break;
case TYPE_UI_HIGHSCORE:
((Game) Gdx.app.getApplicationListener()).setScreen(new HighScoresScreen(getMyGame(),"Highscore Screen"));
break;
case TYPE_UI_CREDIT:
((Game) Gdx.app.getApplicationListener()).setScreen(new CreditsScreen(getMyGame(),"Credit Screen"));
break;
case TYPE_UI_INSTRUCTION:
((Game) Gdx.app.getApplicationListener()).setScreen(new PreGameScreen(getMyGame(), "Tutorial Screen"));
break;
case TYPE_GAME:
((Game) Gdx.app.getApplicationListener()).setScreen(new GameScreen(getMyGame(), "Game Screen"));
break;
}
}
}
else
{
}
}
@Override
public void hide()
{
getMyGame().getManager().unloadGroup("loading_screen");
}
}
您是否嘗試過調試(在手機上仍然連接到計算機時在其上運行應用程序)以確保不會錯過打印到日誌中的錯誤? –
你說你不使用兩個PNG的能力。我會先試驗一下 - 我曾經有過仿真器不在乎但是真正的設備在那裏的經驗。設備使用各種圖形驅動程序並堅持PoT始終是一個好主意。 – NigelK
@NigelK我知道鍋,這是我的第一選擇,但問題仍然存在,遊戲只裝4出10頁的圖冊,但現在它加載了8 10. –