Reputation: 616
I'm willing to fully exploit the AssetManager from Libgdx and all its Loaders. But i have problem understanding this so special link between Skin and TextureAtlas.
I want to use the JSON way of creating skins as much as possible.
In the wiki i can read this :
Note the JSON does not describe texture regions, ninepatche splits, or other information which comes from the texture atlas
In the SkinLoader page i read this :
AssetLoader for Skin instances. (1)All Texture and BitmapFont instances will be loaded as dependencies. Passing a SkinLoader.SkinParameter allows the (2)exact name of the texture associated with the skin to be specified. Otherwise the skin texture is looked up just as with a call to (3)Skin.Skin(com.badlogic.gdx.files.FileHandle). A SkinLoader.SkinParameter also allows named resources to be set that will be added to the skin before loading the json file, meaning that they can be referenced from inside the json file itself. This is useful for dynamic resources such as a BitmapFont generated through FreeTypeFontGenerator.
So here is what where my thoughts when i read this.
(1) All texture. They use the plural so i guess they're mentioning the texture (as a drawable) that i may need for a button, for example.
(2) The exact name of THE texture. So now, maybe they're talking about the TextureAtlas, because SkinParameter as only two fields resources and textureAtlasPath.
(3) This seems to confirm the (2)
So if i understand, if i want to use this method to load my Skin i MUST use the TexturePacker and the TextureAtlas.
Can you confirm me that i understood that correctly and that there are NO WAY of initializing the texture which will be used in my skin without a TextureAtlas but with simple png files ?
And if use the TexturePacker to create my pack file, obviously i will have to repack everything when i make a modification on one of my texture, right ?
Upvotes: 1
Views: 2248
Reputation: 93609
Skin does support using separate Textures for your various drawables, but it's clunky because it's not really something anyone should be doing. What you could do is create TextureRegion drawables out of your Textures, and register them by name with the Skin before telling the skin to load the json file, like this:
TextureRegionDrawable someButtonImage = new TextureRegionDrawable(
new TextureRegion(someButtonTextureThatIsAlreadyLoaded));
Skin skin = new Skin(); //don't give it a json file yet
skin.add("someButton", someButtonImage);
skin.load(Gdx.files.internal("mySkin.json"));
Now your Json could use "someButton" as a value for any drawable paramter in the skin.
But if you're using AssetManager, you can only do this if you have already loaded all your necessary textures outside of the AssetManager, so you can pass them into your SkinLoader's SkinParameter as a Map of names to TextureRegionDrawables.
Either way, you would be typing a lot of code to manually load all those textures, when you could just be using a texture atlas, which will perform better anyway. You can set up your run configuration in your IDE to pack your atlas for you each time you start your app, if you're concerned about having to do that every time you change an image in your skin.
The exception to all the above is for BitmapFonts, which do not have to be part of the same atlas as everything else for you to be able to load them purely from Json. Skin treats it as a special case.
Anyway, here's how I load my skin along with the atlas it uses to retrieve its drawables:
assetManager.load("mySkin.json", Skin.class, new SkinLoader.SkinParameter("myAtlas.atlas"));
Upvotes: 2