簡體   English   中英

LibGDX游戲可以在桌面上正常運行,但不能在Android設備上運行

[英]LibGDX Game Works as Expected on Desktop, But Not on Android Device

我遇到了一個問題。 我對libGDX有點陌生,對出錯的地方一無所知。
在這里,我有一個具有三個文本按鈕實例的狀態。 它可以在我的桌面上正常工作,但在手機上崩潰。 我不確定是什么問題,但是當我注釋掉其中兩個實例的代碼時,它可以在我的手機上運行。

public class MenuStateTest extends State {

Stage stage;
TextButton button, button2, button3;
TextButton.TextButtonStyle textButtonStyle;
BitmapFont font;
Skin skin;
TextureAtlas buttonAtlas, button2Atlas, button3Atlas;

public MenuStateTest(GameStateManager gsm) {
    super(gsm);
    stage = new Stage();
    Gdx.input.setInputProcessor(stage);
    font = new BitmapFont();
    skin = new Skin();

    buttonAtlas = new TextureAtlas("buttonTest.pack");
    skin.addRegions(buttonAtlas);
    textButtonStyle = new TextButton.TextButtonStyle();
    textButtonStyle.font = font;
    textButtonStyle.up = skin.getDrawable("1BBlock");
    textButtonStyle.down = skin.getDrawable("T1BBlock");
    button = new TextButton("", textButtonStyle);
    stage.addActor(button);
    button.setPosition(20,200);

    button2Atlas = new TextureAtlas("button2Test.pack");
    skin.addRegions(button2Atlas);
    textButtonStyle = new TextButton.TextButtonStyle();
    textButtonStyle.font = font;
    textButtonStyle.up = skin.getDrawable("2BBlock");
    textButtonStyle.down = skin.getDrawable("T2BBlock");
    button2 = new TextButton("", textButtonStyle);
    stage.addActor(button2);
    button2.setPosition(175,200);

    button3Atlas = new TextureAtlas("button3Test.pack");
    skin.addRegions(button3Atlas);
    textButtonStyle = new TextButton.TextButtonStyle();
    textButtonStyle.font = font;
    textButtonStyle.up = skin.getDrawable("3BBlock");
    textButtonStyle.down = skin.getDrawable("T3BBlock");
    button3 = new TextButton("", textButtonStyle);
    stage.addActor(button3);
    button3.setPosition(330,200);
}

@Override
protected void render(SpriteBatch sb) {
    stage.draw();

任何幫助,將不勝感激。
謝謝。

編輯:這就是我能夠從logcat得到的

03-23 11:44:54.510 25775-25799/? E/AndroidRuntime: FATAL EXCEPTION: GLThread 2379
                                               Process: com.mygame.game.android, PID: 25775
                                               Theme: themes:{default=overlay:com.blazze11.euphoria.dark, iconPack:system, fontPkg:system, com.android.systemui=overlay:com.blazze11.euphoria.dark, com.android.systemui.navbar=overlay:system}
                                               com.badlogic.gdx.utils.GdxRuntimeException: Error reading file: button2Test.pack (Internal)
                                                   at com.badlogic.gdx.backends.android.AndroidFileHandle.read(AndroidFileHandle.java:77)
                                                   at com.badlogic.gdx.graphics.g2d.TextureAtlas$TextureAtlasData.<init>(TextureAtlas.java:103)
                                                   at com.badlogic.gdx.graphics.g2d.TextureAtlas.<init>(TextureAtlas.java:231)
                                                   at com.badlogic.gdx.graphics.g2d.TextureAtlas.<init>(TextureAtlas.java:226)
                                                   at com.badlogic.gdx.graphics.g2d.TextureAtlas.<init>(TextureAtlas.java:216)
                                                   at com.badlogic.gdx.graphics.g2d.TextureAtlas.<init>(TextureAtlas.java:211)
                                                   at com.mygame.game.States.MenuStateTest.<init>(MenuStateTest.java:41)
                                                   at com.mygame.game.MyGame.create(MyGame.java:29)
                                                   at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:243)
                                                   at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1519)
                                                   at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240)
                                                Caused by: java.io.FileNotFoundException: button2Test.pack
                                                   at android.content.res.AssetManager.openAsset(Native Method)
                                                   at android.content.res.AssetManager.open(AssetManager.java:331)
                                                   at android.content.res.AssetManager.open(AssetManager.java:305)
                                                   at com.badlogic.gdx.backends.android.AndroidFileHandle.read(AndroidFileHandle.java:75)
                                                   at com.badlogic.gdx.graphics.g2d.TextureAtlas$TextureAtlasData.<init>(TextureAtlas.java:103) 
                                                   at com.badlogic.gdx.graphics.g2d.TextureAtlas.<init>(TextureAtlas.java:231) 
                                                   at com.badlogic.gdx.graphics.g2d.TextureAtlas.<init>(TextureAtlas.java:226) 
                                                   at com.badlogic.gdx.graphics.g2d.TextureAtlas.<init>(TextureAtlas.java:216) 
                                                   at com.badlogic.gdx.graphics.g2d.TextureAtlas.<init>(TextureAtlas.java:211) 
                                                   at com.mygame.game.States.MenuStateTest.<init>(MenuStateTest.java:41) 
                                                   at com.mygame.game.MyGame.create(MyGame.java:29) 
                                                   at com.badlogic.gdx.backends.android.AndroidGraphics.onSurfaceChanged(AndroidGraphics.java:243) 
                                                   at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1519) 
                                                   at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1240) 

如果它在台式機上運行,​​而不能在Android上運行,那么我可以想到兩種可能性:

  1. 檢查包含button2Test.pack文件的文件夾的路徑。 Android路徑是相對於資產文件夾的,而桌面使用相對於根文件夾的路徑。
  2. 檢查文件button2Test.pack的名稱button2Test.pack ,例如,是否應為Button2Test.packbutton2test.PACK或類似的組合。 因為Windows接受任何大小寫文件,但Android不接受。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM