2016-02-16 55 views
1

我正在嘗試爲我的朋友和我正在嘗試製作的遊戲創建主菜單。我們使用Eclipse + LibGdx,並且我真的不知道我在做什麼。我直接使用代碼,並且我一直無法在任何博客/論壇/教程中找到任何幫助。 (http://www.gamefromscratch.com/post/2015/02/03/LibGDX-Video-Tutorial-Scene2D-UI-Widgets-Layout-and-Skins錯誤讀取文件skin.json libgdx

 
    package com.mygdx.game; 
    import com.badlogic.gdx.ApplicationAdapter; 
    import com.badlogic.gdx.Gdx; 
    import com.badlogic.gdx.graphics.GL20; 
    import com.badlogic.gdx.graphics.Texture; 
    import com.badlogic.gdx.graphics.g2d.SpriteBatch; 
    import com.badlogic.gdx.scenes.scene2d.InputEvent; 
    import com.badlogic.gdx.scenes.scene2d.Stage; 
    import com.badlogic.gdx.scenes.scene2d.ui.Dialog; 
    import com.badlogic.gdx.scenes.scene2d.ui.Skin; 
    import com.badlogic.gdx.scenes.scene2d.ui.TextButton; 
    import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; 
    import com.badlogic.gdx.utils.Timer; 
    import com.badlogic.gdx.utils.viewport.ScreenViewport; 

    public class MyGdxGame extends ApplicationAdapter { 
    private Skin skin; 
    private Stage stage; 

    @Override 
    public void create() { 

    skin = new Skin(Gdx.files.internal("uiskin.json")); 
    stage = new Stage(new ScreenViewport()); 

    final TextButton button = new TextButton("Click Me",skin,"default"); 
    button.setWidth(200); 
    button.setHeight(50); 

    final Dialog dialog = new Dialog("Click Message",skin); 

    button.addListener(new ClickListener(){ 
     @Override 
     public void clicked(InputEvent event, float x, float y) { 
      dialog.show(stage); 
      Timer.schedule(new Timer.Task() { 
      @Override 
      public void run() { 
       dialog.hide(); 
      } 
      }, 10); 
     } 
    }); 
    stage.addActor(button); 

    Gdx.input.setInputProcessor(stage); 
} 

    @Override 
    public void render() { 
    Gdx.gl.glClearColor(0, 0, 0, 1); 
    Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); 
    stage.act(Gdx.graphics.getDeltaTime()); 
    stage.draw(); 

} 

    public static void main(String[] args) 
    {;} 
} 

uiskin.json文件:

 
    { 
    com.badlogic.gdx.graphics.g2d.BitmapFont: { default-font: { file: Razer.fnt  } }, 
     com.badlogic.gdx.scenes.scene2d.ui.TextButton$TextButtonStyle: { 
     default: { down: default-round-down, up: default-round, font: default-font  }, 
     }, 

    com.badlogic.gdx.scenes.scene2d.ui.Window$WindowStyle: { 
    default: { 
    titleFont: default-font 
     } 
     } 
    } 

desktoplauncher:

 
    package com.mygdx.game.desktop; 

    import com.badlogic.gdx.backends.lwjgl.LwjglApplication; 
    import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration; 
    import com.mygdx.game.MyGdxGame; 

    public class DesktopLauncher { 
     public static void main (String[] arg) { 
      LwjglApplicationConfiguration config = new  LwjglApplicationConfiguration(); 
     new LwjglApplication(new MyGdxGame(), config); 
    } 
} 

錯誤:

 
Exception in thread "LWJGL Application" com.badlogic.gdx.utils.SerializationException: Error reading file: uiskin.json 
    at com.badlogic.gdx.scenes.scene2d.ui.Skin.load(Skin.java:97) 
    at com.badlogic.gdx.scenes.scene2d.ui.Skin.(Skin.java:74) 
    at com.mygdx.game.MyGdxGame.create(MyGdxGame.java:26) 
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:147) 
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:124) 
Caused by: com.badlogic.gdx.utils.SerializationException: Error reading file: uiskin.json 
    at com.badlogic.gdx.utils.Json.fromJson(Json.java:694) 
    at com.badlogic.gdx.scenes.scene2d.ui.Skin.load(Skin.java:95) 
    ... 4 more 
Caused by: com.badlogic.gdx.utils.SerializationException: Font file not found: Razer.fnt 
    at com.badlogic.gdx.scenes.scene2d.ui.Skin$3.read(Skin.java:452) 
    at com.badlogic.gdx.scenes.scene2d.ui.Skin$3.read(Skin.java:443) 
    at com.badlogic.gdx.utils.Json.readValue(Json.java:884) 
    at com.badlogic.gdx.scenes.scene2d.ui.Skin$1.readValue(Skin.java:408) 
    at com.badlogic.gdx.utils.Json.readValue(Json.java:852) 
    at com.badlogic.gdx.scenes.scene2d.ui.Skin$2.readNamedObjects(Skin.java:429) 
    at com.badlogic.gdx.scenes.scene2d.ui.Skin$2.read(Skin.java:418) 
    at com.badlogic.gdx.scenes.scene2d.ui.Skin$2.read(Skin.java:414) 
    at com.badlogic.gdx.utils.Json.readValue(Json.java:884) 
    at com.badlogic.gdx.scenes.scene2d.ui.Skin$1.readValue(Skin.java:408) 
    at com.badlogic.gdx.utils.Json.fromJson(Json.java:692) 
    ... 5 more 

謝謝。請記住,我完全迷失了,而且是我最後的手段。對於我在這篇文章中犯的任何錯誤感到抱歉!

-ed

回答

1

該錯誤基本上說,皮膚JSON有問題。

雖然格式看起來相當不錯,但我認爲堆棧跟蹤中有更多。請查看Razer.fnt的路徑。

如果沒有解決這個問題,請在這裏粘貼完整的堆棧跟蹤。

0
Font file not found: Razer.fnt 

您必須使用Hiero tool創建一個字體。將Android項目中生成的兩個文件放在Assets文件夾中。如果您沒有「Razer字體」,請在某些字體網站中搜索