默认皮肤LibGDX? [英] Default Skin LibGDX?

查看:159
本文介绍了默认皮肤LibGDX?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在关注此事: https://code.google.com / p / table-layout / #Quickstart ,以便对LibGDX中的表进行一些介绍。我已经用按钮进行了一些实验。

I've been following this: https://code.google.com/p/table-layout/#Quickstart to get a little introduction to tables in LibGDX. I already experimented around a little with buttons.

现在我有了这个代码:

Label introLabel = new Label("Skip Intro", skin);
TextField introText = new TextField("", skin);

table.add(introLabel);
table.add(introText).width(100);
table.row();

但它抛出 NullPointerException 因为:没有注册名称的com.badlogic.gdx.scenes.scene2d.ui.Label $ LabelStyle:default

仅限我将我的按钮(从屏幕中的其他位置)添加到皮肤中:

I only added my buttons (from somewhere else in the screen) into the skin:

atlas = new TextureAtlas("assets/gui/buttons/alpha_generic_buttons.pack");

skin = new Skin();
skin.addRegions(atlas);

我的问题现在是桌子需要什么样的纹理,最重要的是,我如何使用他们用桌子?

My question would now be what kind of textures a table needs and most of all, how do I use them with the table?

推荐答案

说到libGDX中的用户界面,你会发现它与你用过的用途非常不同之前(yaml,json,xml,UI Builders等)。

When it comes to UI in libGDX, you will find its very different than what you would have used before (yaml, json, xml, UI Builders, etc).

表格布局 - 这就是Scene2d UI的结构和格式。你提供的链接是一个很棒的教程,但是你已经意识到,你需要一个皮肤去做大多数事情。

Table Layout - This is how Scene2d UI is structured and formatted. The link you have provided is a great tutorial, but as you have come to realize, you need a skin to do most things.

LibGDX皮肤 - 包含3个内容,一个纹理包图像,一个纹理包文件和一个用于设置样式的Json。您也可以像编程一样以编程方式生成它们,但我发现从文件中加载它们并使用它们要容易得多。如果您想了解有关如何制作皮肤或编辑皮肤等的更多信息,请点击以下链接:皮肤

LibGDX Skin - consists of 3 things, a texture pack image, a texture pack file, and a Json to set up the styles. You can also generate them programmatically like you are doing, but I find it much easier to simply load them from a file and use. If you want to learn more about how to make skins, or edit them, etc follow this link: Skins.

现在,回到你得到的例外。这是因为您创建的皮肤没有用于描述各种UI元素的样式的json。在上述异常的情况下,文本字段内的标签没有默认样式。

Now, back to the exception you are getting. This is because the skin you have created doesn't have the json used to describe the styles for various UI elements. In the case of the above exception, the label inside of the text field doesn't have a default style.

您可以简单地使用提供的模板测试文件夹:

What you can simply do is use the template provided in the tests folder:


  1. Atlaspack文件

  2. Json文件

  3. Atlaspack图片

  4. 字体图片

  5. 字体文件

  1. Atlaspack File
  2. Json File
  3. Atlaspack Image
  4. Font Image
  5. Font File

放这些android项目的assets文件夹中的文件。然后你可以用一行代码轻松加载这个皮肤:

Put these files in the assets folder of your android project. And then you can easily load this skin with one line of code:

Skin uiSkin = new Skin(Gdx.files.internal("uiskin.json"));

这将有缺少信息来制作你的TextField对象,以及一堆其他默认样式:

This will have the missing piece of information to make your TextField object, as well as a bunch of other default styles:

com.badlogic.gdx.scenes.scene2d.ui.Label$LabelStyle: {
    default: { font: default-font, fontColor: white },
}

希望这有助于获取你开始了还有很多其他小事情,所以不要害怕查看 Scene2d.UI 有关更多信息的维基文章。

Hopefully this helps get you started. There are a number of other little things so don't be afraid to look over the Scene2d.UI article on the wiki for more information.

注意:您可以使用 gdx-tools 工件,可以使用默认的UI皮肤开箱即用(对于非常小/简单的应用程序非常有用,用于调试,当您真正急于让UI可见时等)。

Note: You can use gdx-tools artifact to be able to use the default UI skin out-of-the-box (can be quite useful for very small/simple applications, for debugging, when you're in a real rush to have the UI visible, etc).

这篇关于默认皮肤LibGDX?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆