简体   繁体   English

如何使我的游戏的用户界面元素适应libgdx中不同的移动设备屏幕

[英]How can i make my the user interface elements of my game adapt to the different mobile device screen in libgdx

I am working through the book "Java Game Development with libgdx by Lee Stemkoski", All the samples use the desktop to test, I am using the stage class to render actors on the android device display, but when i add actors with images, they extend out of the display of the android device i am testing on. 我正在阅读“ Lee Stemkoski的libgdx进行的Java游戏开发”一书,所有示例都使用桌面进行测试,我正在使用stage类在Android设备显示屏上渲染actor,但是当我添加带图像的actor时,它们扩展到我正在测试的android设备的显示范围之外。 Also, i have the same width and height set up for the desktop and mobile, but some ui elements are truncated in the desktop version but show completely in the android device. 另外,我为台式机和移动设备设置了相同的宽度和高度,但是某些ui元素在台式机版本中被截断,但在android设备中完全显示。 Also, do i have to design my textures with the aspect ratio of the screens i want to support in mind? 另外,我是否必须考虑要支持的屏幕的纵横比来设计纹理? e,g 16:9 screen, what kind sizes of textures should i create?. 例如16:9屏幕,我应该创建哪种尺寸的纹理?

I have tried to create a FitViewport() with the dimensions 800 by 480 and then add it to the stage before calling the stage act and draw methods but this does not effect any change to the game screen. 我尝试创建尺寸为800 x 480的FitViewport() ,然后将其添加到舞台,然后再调用舞台的act和draw方法,但这不会影响游戏屏幕。

What i am trying to achieve is that i want to be able to adapt my ui elements eg actors table textures to the display of the mobile device i am running the game on. 我想要实现的目标是,我希望能够将我的ui元素(例如actor表纹理)调整为我正在运行游戏的移动设备的显示。 Any help on this will be greatly appreciated!. 任何帮助,将不胜感激!

The FitViewPort is the correct way to go. FitViewPort是正确的方法。 If it does not work, you are doing something wrong. 如果它不起作用,则说明您做错了事。 Please share your code. 请分享您的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM