2016-12-05 2 views
0

Aus irgendeinem Grund nach dem Hinzufügen von Schaltflächen zu meiner Anwendung hat es auf Android funktioniert nicht mehr. Es funktioniert wie erwartet auf dem Desktop, aber wenn versucht wird, auf Android zu laufen, baut die App erfolgreich, startet, dann stürzt sie sofort ab, bevor sie überhaupt die Szene lädt. Ich habe versucht, die Protokolle über aLogcat anzuzeigen, jedoch sehe ich in diesen Protokollen nichts, was auf ein Problem hindeutet.libgdx Android App stürzt beim Laden von uiskin | keine Protokolle

Ich bin zu dem Schluss gekommen, dass dieses Problem etwas damit zu tun hat, dass die uiskin/buttons zur Bühne hinzugefügt werden, da ich die Bühne ohne Schauspieler hinzufügen kann und die App weiterhin in android funktioniert. Die in der Datei uiskin.json angegebenen Dateien befinden sich alle im Verzeichnis/android/assets, so wie sie sein sollten. Habe ich etwas falsch gemacht? Etwas, das ich vermisst habe?

uiskin.json

{ 
    "com.badlogic.gdx.graphics.g2d.BitmapFont":{ 
     "default_font": { 
      "file": "book_antiqua.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" 
     } 
    } 
} 

Hauptklasse

package com.freedom.thirty; 

import com.badlogic.gdx.ApplicationListener; 
import com.badlogic.gdx.Gdx; 
import com.badlogic.gdx.InputMultiplexer; 
import com.badlogic.gdx.assets.AssetManager; 
import com.badlogic.gdx.graphics.Color; 
import com.badlogic.gdx.graphics.GL20; 
import com.badlogic.gdx.graphics.PerspectiveCamera; 
import com.badlogic.gdx.graphics.OrthographicCamera; 
import com.badlogic.gdx.graphics.VertexAttributes.Usage; 
import com.badlogic.gdx.graphics.g3d.Environment; 
import com.badlogic.gdx.graphics.g3d.Model; 
import com.badlogic.gdx.graphics.g3d.ModelBatch; 
import com.badlogic.gdx.graphics.g3d.ModelInstance; 
import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute; 
import com.badlogic.gdx.graphics.g3d.environment.DirectionalLight; 
import com.badlogic.gdx.graphics.g3d.Material; 
//import com.badlogic.gdx.graphics.g3d.utils.CameraInputController; 
import com.badlogic.gdx.graphics.g3d.utils.ModelBuilder; 
import com.badlogic.gdx.utils.Array; 
import com.badlogic.gdx.graphics.FPSLogger; 
import com.badlogic.gdx.scenes.scene2d.InputEvent; 
import com.badlogic.gdx.scenes.scene2d.Stage; 
import com.badlogic.gdx.scenes.scene2d.ui.Skin; 
import com.badlogic.gdx.scenes.scene2d.ui.Table; 
import com.badlogic.gdx.scenes.scene2d.ui.TextButton; 
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; 
import com.badlogic.gdx.utils.Align; 
import com.badlogic.gdx.utils.viewport.FillViewport; 
import com.badlogic.gdx.utils.viewport.ScreenViewport; 
import com.badlogic.gdx.utils.viewport.Viewport; 

import com.freedom.thirty.MyCameraInputController; 


public class FreedomThirty implements ApplicationListener { 

    public ScreenViewport vp; 
    public ScreenViewport stageVp; 

    public OrthographicCamera cam; 
    public MyCameraInputController camController; 
    public ModelBatch modelBatch; 
    public AssetManager assets; 
    public Array<ModelInstance> allModelInstances = new Array<ModelInstance>(); 
    public Environment environment; 
    public boolean loading; 


    // Model instances that make up the map 
    public ModelInstance bridge; 
    public ModelInstance container_001; 
    public ModelInstance crate_001; 
    public ModelInstance crate_002; 
    public ModelInstance crate_003; 
    public ModelInstance crate_004; 
    public ModelInstance crate_005; 
    public ModelInstance grass_area; 
    public ModelInstance gravel_area; 
    public ModelInstance rock_wall; 
    public ModelInstance water; 
    public ModelInstance player; 
    public ModelInstance skybox; 

    public Skin skin; 
    public Stage stage; 
    public Table table; 


    //public FPSLogger fpsLogger = new FPSLogger(); 


    @Override 
    public void create() { 

     modelBatch = new ModelBatch(); 
     assets = new AssetManager(); 
     environment = new Environment(); 
     environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.8f, 0.8f, 0.8f, 1f)); 
     //environment.add(new DirectionalLight().set(0.8f, 0.8f, 0.8f, -1f, -0.8f, -0.2f)); 

     cam = new OrthographicCamera(); 
     cam.position.set(-4f, 4f, 4f); 
     cam.lookAt(8f, 0f, -8f); 
     cam.near = 1f; 
     cam.far = 2000f; 
     cam.update(); 

     // Create input controller for default scene camera. This is what allows the user to orbit around the scene 
     camController = new MyCameraInputController(cam); 
     // Set the position where the camera will look. This will need to come from json config file in the future 
     camController.target.set(8f, 0f, -8f); 

     vp = new ScreenViewport(cam); 
     vp.setUnitsPerPixel(0.017f); 
     vp.apply(); 


     stageVp = new ScreenViewport(); 
     stageVp.apply(); 
     stage = new Stage(stageVp); 


     assets.load("uiskin.json", Skin.class); 
     assets.load("map_003.g3db", Model.class); 
     loading = true; 

    } 

    private void doneLoading(){ // Assets are now loaded into memory and can be accessed without error 

     // Load UI skin 
     skin = assets.get("uiskin.json", Skin.class); 

     // Define the buttons that will be in the ui table 
     final TextButton zoomOut = new TextButton("Zoom Out",skin,"default"); 
     final TextButton zoomIn = new TextButton("Zoom In",skin,"default"); 

     // Create UI table actor 
     table = new Table(); 
     table.setWidth(stage.getWidth()); 
     table.align(Align.center | Align.top); 

     // In the future determine what the current viewport height/width is, and set these 
     // to different sizes based on where the viewport falls between. Just like bootstrap's xs,sm,md,lg classes 
     table.setSize(250f, 250f); 
     table.setPosition(800f,400f); 

     zoomOut.setWidth(200); 
     zoomOut.setHeight(50); 

     zoomIn.setWidth(200); 
     zoomIn.setHeight(50); 

     // Event listeners for ui buttons 
     zoomOut.addListener(new ClickListener(){ 

      @Override 
      public void clicked(InputEvent event, float x, float y){ 
       //Gdx.app.log("Zoom Out", "Press successful"); 
       vp.setUnitsPerPixel(vp.getUnitsPerPixel() + 0.001f); 

       vp.update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); 
       stageVp.update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); 

       event.stop(); 
      } 

     }); 
     zoomIn.addListener(new ClickListener(){ 

      @Override 
      public void clicked(InputEvent event, float x, float y){ 
       //Gdx.app.log("Zoom In", "Press successful"); 
       vp.setUnitsPerPixel(vp.getUnitsPerPixel() - 0.001f); 

       vp.update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); 
       stageVp.update(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); 

       event.stop(); 
      } 

     }); 


     // Add buttons to table 
     table.row().padBottom(30).padTop(30); 
     table.add(zoomOut); 
     table.add(zoomIn); 

     // Add table to stage 
     stage.addActor(table); 



     // Create an input multiplexer and add our stage and camController to it, set input processor to our new multiplexer 
     InputMultiplexer im = new InputMultiplexer(stage, camController); 
     Gdx.input.setInputProcessor(im); 


     // Load the 3d map, and character as character happens to be in the map file as of right now 
     // In the future each map and it's elements will be contained within it's own class, extended from 
     // map class 
     Model model = assets.get("map_003.g3db", Model.class);   

     bridge = new ModelInstance(model, "bridge"); 
     allModelInstances.add(bridge); 

     container_001 = new ModelInstance(model, "container_001"); 
     allModelInstances.add(container_001); 

     crate_001 = new ModelInstance(model, "crate_001"); 
     allModelInstances.add(crate_001); 
     crate_002 = new ModelInstance(model, "crate_002"); 
     allModelInstances.add(crate_002); 
     crate_003 = new ModelInstance(model, "crate_003"); 
     allModelInstances.add(crate_003); 
     crate_004 = new ModelInstance(model, "crate_004"); 
     allModelInstances.add(crate_004); 
     crate_005 = new ModelInstance(model, "crate_005"); 
     allModelInstances.add(crate_005); 

     grass_area = new ModelInstance(model, "grass_area"); 
     allModelInstances.add(grass_area); 

     gravel_area = new ModelInstance(model, "gravel_area"); 
     allModelInstances.add(gravel_area); 

     rock_wall = new ModelInstance(model, "rock_wall"); 
     allModelInstances.add(rock_wall); 

     water = new ModelInstance(model, "water"); 
     allModelInstances.add(water); 

     player = new ModelInstance(model, "character"); 
     allModelInstances.add(player); 


     player.transform.setTranslation(8f,0f,-6f); // Test character movement on the map 

     loading = false;   

    } 

    @Override 
    public void render() { 

     if(loading && assets.update()){ 
      doneLoading(); 
     } 

     Gdx.gl.glViewport(0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); 
     Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT); 


     camController.update(); 

     //Gdx.app.log("Camera Position: ", cam.position.toString()); 

     modelBatch.begin(cam); 
     modelBatch.render(allModelInstances, environment); 
     modelBatch.end(); 

     stage.act(Gdx.graphics.getDeltaTime()); 
     stage.draw(); 

     //fpsLogger.log(); 

    } 

    @Override 
    public void dispose() { 

     modelBatch.dispose(); 
     allModelInstances.clear(); 
     assets.dispose(); 

    } 

    @Override 
    public void resize(int width, int height) { 

     vp.update(width, height); 
     stageVp.update(width, height); 

    } 

    @Override 
    public void pause() { 
    } 

    @Override 
    public void resume() { 
    } 

} 

Antwort

1

Was schließlich dieses Problem behoben wurde, war das Herunterladen der Standard-Uiskin-Dateien von der libgdx repository on github. Anscheinend habe ich etwas verpasst, als ich sie von Grund auf neu gebaut habe? Die Dateien, die ich aus dem Repo verwendet werden:

  • uiskin.json
  • uiskin.atlas
  • default.png
  • uiskin.png
0

Ich denke, es zu lange dauert, die uiskin Datei zu laden. Versuchen Sie statt skin = new Skin(Gdx.files.internal("uiskin.json")); etwas wie folgt aus:

AssetManager manager = new AssetManager(); manager.load("uiskin.json", Skin.class); manager.finishLoading(); skin = manager.get("uiskin.json", Skin.class);

Vergessen Sie nicht, den Assetmanager, zu entsorgen, wenn, bevor Sie Ihr Spiel zu beenden.

+0

Ich hatte große Hoffnungen für dieses, aber leider Das Problem besteht weiterhin. Ich werde meinen Code oben aktualisieren. – commanderZiltoid