Libgdx使用uiskin.json创建一个带背景的TextButton

时间:2015-05-10 09:22:17

标签: java libgdx scene2d

我想用uiskin.json定义TextButton的背景。

这是我尝试过但没有工作的内容:

wordcloud

所以我想把bg.png作为默认背景。我该怎么办?

1 个答案:

答案 0 :(得分:2)

皮肤无法从json读取文件位置。如果你学习了Skin的教程,你可能会使用像这样的TextureAtlas实例化它:

skin = new Skin(skinFilePath, textureAtlas);

当您像这样加载它时,json中的所有图像必须可以通过TextureAtlas中的名称获得。

通常,出于性能原因,您需要将所有图像放在单个TextureAtlas中。所以最好的解决方案是将这个bg.png图像添加到TextureAtlas中,然后你可以通过它的TextureAtlas名称来引用它。

如果您必须将其作为单独的文件加载,则必须在加载皮肤之前手动加载它。

Texture bgTexture = new Texture("bg.png");
skin = new Skin(); //empty constructor causes it not to load yet.
skin.add("bg", bgTexture);
skin.addRegions(textureAtlas); // you will be responsible for disposing the atlas separately from the skin now.
skin.load(skinFilePath);