Java 默认皮肤 LibGDX?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16182844/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-16 05:39:13  来源:igfitidea点击:

Default Skin LibGDX?

javalayoutlibgdx

提问by AreusAstarte

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

我一直在关注这个:https: //code.google.com/p/table-layout/#Quickstart以了解 LibGDX 中的表格。我已经尝试了一些按钮。

Now I have this code:

现在我有这个代码:

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

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

But it throws a NullPointerExceptionbecause: No com.badlogic.gdx.scenes.scene2d.ui.Label$LabelStyle registered with name: default

但它抛出一个NullPointerException因为:No com.badlogic.gdx.scenes.scene2d.ui.Label$LabelStyle registered with name: 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?

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

采纳答案by Jyro117

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).

当谈到 libGDX 中的 UI 时,您会发现它与您之前使用的(yaml、json、xml、UI Builders 等)非常不同。

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.

表格布局- 这是 Scene2d UI 的结构和格式。您提供的链接是一个很好的教程,但正如您所意识到的,您需要一个皮肤来做大多数事情。

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.

LibGDX 皮肤- 由 3 个东西组成,一个纹理包图像、一个纹理包文件和一个用于设置样式的 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.

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

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

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

  1. Atlaspack File
  2. Json File
  3. Atlaspack Image
  4. Font Image
  5. Font File
  1. Atlaspack 文件
  2. JSON文件
  3. Atlaspack 图像
  4. 字体图片
  5. 字体文件

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

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

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

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

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

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

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

希望这有助于您入门。还有许多其他小东西,所以不要害怕查看wiki上的Scene2d.UI文章以获取更多信息。

Note:You can use gdx-toolsartifact to be able to use the default UI skinout-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).

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

回答by Quentin Oxydeme Kunstler

Or if you want to create your very own, Raleus made up a skin editor, Pretty friendly Ui, simple to use, results are awesome https://github.com/raeleus/skin-composerOnce you navigate threw it a bit you understand much more about skins and how tu use'em

或者如果你想创建自己的皮肤编辑器,Raleus 制作了一个皮肤编辑器,UI 非常友好,使用简单,效果很棒 https://github.com/raeleus/skin-composer一旦你导航扔了它你就明白了更多关于皮肤以及你如何使用它们