-1
我最近添加了一個AssetManager類到我的LibGDX遊戲,但我似乎無法讓它工作。LibGDX AssetManager沒有加載任何東西
這裏是我的AssetManager類:
public class AssetLoader {
public AssetManager manager = new AssetManager();
public void loadAssets(){
manager.load("antoanimation.png", Texture.class);
manager.load("antoButton.png", Texture.class);
manager.load("bg2.png", Texture.class);
manager.load("bottomtube2.png", Texture.class);
manager.load("clickme.png", Texture.class);
manager.load("diamtermopan.png", Texture.class);
manager.load("gameover.png", Texture.class);
manager.load("grass.png", Texture.class);
manager.load("logo.png", Texture.class);
manager.load("menubutton.png", Texture.class);
manager.load("pausebutton.png", Texture.class);
manager.load("pausemenu.png", Texture.class);
manager.load("play.png", Texture.class);
manager.load("restartbutton.png", Texture.class);
manager.load("return.png", Texture.class);
manager.load("selected.png", Texture.class);
manager.load("shopbutton.png", Texture.class);
manager.load("shopLayout.png", Texture.class);
manager.load("termopanButton.png", Texture.class);
manager.load("vladanimation.png", Texture.class);
manager.load("vladButton.png", Texture.class);
}
public void dispose(){
manager.dispose();
}
這是我主要的遊戲類:
public class FlappyPela extends ApplicationAdapter {
public static SpriteBatch batch;
private GameStateManager gsm;
private AssetLoader assets;
@Override
public void create() {
batch = new SpriteBatch();
gsm = new GameStateManager();
assets = new AssetLoader();
assets.loadAssets();
assets.manager.finishLoading();
gsm.push(new MenuState(gsm));
}
@Override
public void render() {
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
super.render();
}
@Override
public void dispose() {
super.dispose();
assets.manager.dispose();
batch.dispose();
}
}
這是我的菜單類:
public class MenuState extends State {
private Texture background;
private Sprite logo;
private Sprite clickme;
PlayButton play;
Viewport viewport;
public MenuState(GameStateManager gsm) {
super(gsm);
background = new Texture("bg2.png");
play = new PlayButton();
logo = new Sprite(new Texture(Gdx.files.internal("logo.png")));
clickme = new Sprite(new Texture(Gdx.files.internal("clickme.png")));
viewport = new StretchViewport(720, 1280, cam);
viewport.apply();
cam.position.set(cam.viewportWidth/2, cam.viewportHeight/2,0);
logo.setSize(620, cam.viewportHeight/2 - 200);
logo.setPosition(cam.viewportWidth/2 - logo.getWidth()/2 , cam.viewportHeight/2 + 100);
clickme.setSize(460, 450);
clickme.setPosition(225, 125);
}
@Override
public void handleInput() {
if(play.isPressed()){
gsm.set(new PlayState(gsm));
}
}
@Override
public void update(float dt) {
handleInput();
cam.update();
}
@Override
public void resize(int width, int height){
viewport.update(width, height);
cam.position.set(cam.viewportWidth/2, cam.viewportHeight/2,0);
}
@Override
public void render(SpriteBatch sb) {
cam.update();
sb.setProjectionMatrix(cam.combined);
Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
sb.begin();
sb.draw(background, 0, 0, cam.viewportWidth, cam.viewportHeight);
logo.draw(sb);
clickme.draw(sb);
sb.end();
play.act();
play.draw();
}
@Override
public void dispose() {
background.dispose();
logo.getTexture().dispose();
clickme.getTexture().dispose();
}
}
當我開始模擬器,它只是顯示黑屏,然後我的整個程序崩潰!我究竟做錯了什麼?
顯示你的崩潰報告? – Aryan
您沒有使用/從AssetManger獲取您創建的數據。 – Aryan
另外我需要你的狀態類的代碼? – Aryan