英文:
LibGDX Scene2D a different way of implementing a GUI scale setting other than multiplying everything by a constant?
问题
我有一堆游戏的 UI 元素。我有一个物品清单、HUD、快捷栏、游戏内菜单等等。现在我想根据设置来对它们进行缩放。我从文件中导入设置,然后将其放入一个全局变量中,供 UI 元素使用。目前我处理这个问题的方式是将 UI 舞台所有子元素的位置、宽度和高度都乘以这个全局变量。然而,这种方式并不是很实用或可维护。所以我想知道是否有其他的方法?我想也许有一个内置的缩放选项?不过很遗憾,我在网上没有找到关于这个的任何信息,因为搜索词 "scaling" 得到的都是许多其他不太相关但更常见的问题和解决方案。
英文:
I have a bunch of UI elements for my game. I have an inventory, HUD, hotbar, in-game menu etc. Now I want to scale these based on a setting. I import the settings from a file and basically put it in a global variable, which can be used by the UI elements. Currently the way I'm going about this is multiplying every position, width and height of all children of the UI Stages by this global variable. This isn't very practical or maintainable, though. So I was wondering if there's another way to go about this? I figured maybe there is a built in scaling option? Sadly I wasn't able to find anything about this online since the search term "scaling" results in a ton of different, more common, questions/solutions.
答案1
得分: 0
如果您正在使用Scene2D
,您可能有一个包含所有其他UI组件的根Actor
。您只需要将比例属性设置为根Actor
。
float scale = ...; //XY比例
Actor root = ...;
root.setScale(scale);
英文:
If you are using Scene2D
you probably have a root Actor
that contains all the other UI components. You just need to set the scale property to the root Actor
.
float scale = ...; //XY scale
Actor root = ...;
root.setScale(scale);
专注分享java语言的经验与见解,让所有开发者获益!
评论