2
votes

I'm currently trying to build a simple loading screen for my game and am trying to get a skin for a font.

When I try to get the the skin though, with skin = game.manager.get("bin/ui/loading.json", Skin.class);, this error occurs:

Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: com.badlogic.gdx.utils.GdxRuntimeException: File not found: bin\ui\loadingSkin.atlas (Internal)
at com.badlogic.gdx.assets.AssetManager.handleTaskError(AssetManager.java:540)
at com.badlogic.gdx.assets.AssetManager.update(AssetManager.java:356)
at com.badlogic.gdx.assets.AssetManager.finishLoading(AssetManager.java:377)
at com.Sidescroll.game.LoadingScreen.show(LoadingScreen.java:32)
at com.badlogic.gdx.Game.setScreen(Game.java:61)
at com.Sidescroll.game.Sidescroll.create(Sidescroll.java:20)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:143)
at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:120)
Caused by: com.badlogic.gdx.utils.GdxRuntimeException: File not found: bin\ui\loadingSkin.atlas (Internal)
at com.badlogic.gdx.files.FileHandle.read(FileHandle.java:136)
at com.badlogic.gdx.graphics.g2d.TextureAtlas$TextureAtlasData.<init>(TextureAtlas.java:103)
at com.badlogic.gdx.assets.loaders.TextureAtlasLoader.getDependencies(TextureAtlasLoader.java:58)
at com.badlogic.gdx.assets.loaders.TextureAtlasLoader.getDependencies(TextureAtlasLoader.java:34)
at com.badlogic.gdx.assets.AssetLoadingTask.handleSyncLoader(AssetLoadingTask.java:98)
at com.badlogic.gdx.assets.AssetLoadingTask.update(AssetLoadingTask.java:87)
at com.badlogic.gdx.assets.AssetManager.updateTask(AssetManager.java:477)
at com.badlogic.gdx.assets.AssetManager.update(AssetManager.java:354)
... 6 more

In my current assets/ui folder are 5 files:

loading_0.png - BitmapFont image

loading.fnt - Font file

loading.pack - used TexturePacker to pack the single image

loading.png - TexturePacker image

loadingSkin.json - Skin.json, where BitmapFont and LabelStyle is described

The part where Im trying to use assetmanager:

//this is the beginning of the show method of my loadingScreen, nothing
//happened before

game.manager.load("bin/ui/loading.pack", TextureAtlas.class);
game.manager.finishLoading();
atlas = game.manager.get("bin/ui/loading.pack");
// do i need an atlas here ?
game.manager.load("bin/ui/loadingSkin.json", Skin.class);
game.manager.finishLoading();

skin = game.manager.get("bin/ui/loading.json", Skin.class);

Question is, do I always need an atlas? if yes, how do I create one, if not, why does the error occur?

EDIT: I'm using release 1.5.4 of libgdx and do not have android in my project

2

2 Answers

1
votes

the Skin has many various contructors like:

    Skin()
    Skin(FileHandle skinFile)
    Skin(FileHandle skinFile, TextureAtlas atlas)
    Skin(TextureAtlas atlas)

If you are using the JSON version of constructor you are just passing the json configuration file to it. Skin needs to have some texture atlas so with this option by default it is looking for the .atlas file named exatcly like json file. It means that when you are using file name loadingSkin.json:

    game.manager.load("bin/ui/loadingSkin.json", Skin.class);

it will look for the loadingSkin.atlas file and because there is nothing like this it causes the error.

Now you have two option:

  • create file named like your json but with atlas extension (.atlas is exactly like .pack - you can just change extension or create a file with .atlas instead of .pack in TexturePacker)

    loading.pack -> loading.atlas
    

    When changing names be aware of you texture .png file! (The .pack/.atlas file has its name inside - check with editor)

  • use another constructor of skin like:

    Skin(FileHandle skinFile, TextureAtlas atlas)
    

    You are passing filehandle to .json and TextureAtlas instance of the skin texture

    TextureAtlas atlas = game.manager.get("bin/ui/loading.pack", TextureAtlas.class);
    
    Skin skin = new Skin( Gdx.files.internal("bin/ui/loadingSkin.json"), atlas);
    
1
votes

This line causes the error:

game.manager.load("bin/ui/loadingSkin.json", Skin.class);

When I looked into SkinLoader class' source I've seen that it loads the file by appending .atlas by default:

@Override
public Skin loadSync (AssetManager manager, String fileName, FileHandle file, SkinParameter parameter) {
    String textureAtlasPath = file.pathWithoutExtension() + ".atlas";
...

So it seems like you need a TextureAtlas for your skin. You can create TextureAtlas by using https://libgdx-texturepacker-gui.googlecode.com/files/gdx-texturepacker-3.2.0.zip

You can create a TextureAtlas named loadingSkin.atlas and put it under bin\ui\loadingSkin.atlas. If you want to create an atlas with another name and tell the loader which TextureAtlas to use, you can pass SkinParameter to your load method:

SkinLoader.SkinParameter loadingSkinParameter = new SkinLoader.SkinParameter();
loadingSkinParameter.textureAtlasPath = "YOUR_TEXTURE_ATLAS_PATH";
game.manager.load("bin/ui/loadingSkin.json", Skin.class, loadingSkinParameter);