Android libgdx big screen resolution(Android libgdx 大屏分辨率)
问题描述
如何支持(制定算法)libgdx 以支持多种屏幕分辨率?我使用带有以下参数的 if 语句使我的应用程序在 HTC Tattoo 上运行:
How can I support (make an algorithm) for libgdx for supporting multiple screen resolution? I made my app work on HTC Tattoo using if statments with parameters like:
if (Gdx.input.getX()==40) {
在更大的屏幕上进行这项工作的好算法是什么?我试过了,但没有任何结果:
What is a good algorithm for making this work on bigger screens? I tried this but without any result:
publis static int translatex() {
float p = (float)Gdx.graphics.getHeight()*340;
return (int) p*Gdx.input.getX();
}
340 是我在 HTC Tattoo 上使用的基本 x(我手机上的 x 分辨率).那么.....我怎样才能制作一个支持具有绝对值的大屏幕的功能.我不想更改 if 语句.
340 is the base x (the x resolution on my phone) used by me on the HTC Tattoo. So.....how can I make a function for supporting big screens with absolute values. I don`t want to change the if-statements.
推荐答案
很简单.你基本上是为你的原始分辨率构建你的整个程序,但是在处理定位和纹理大小的所有事情中都有这样的东西:
It's pretty easy. You basically build your entire program for your native resolution, but in everything dealing with positioning and texture sizing have something like this:
private void resize()
{
float x = Gdx.graphics.getWidth();
float y = Gdx.graphics.getHeight();
float changeX = x / assumeX; //being your screen size that you're developing with
float changeY = y / assumeY;
position = new Vector2(position.x * changeX, position.y * changeY);
width = startWidth * changeX;
height = startHeight * changeY;
bounds = new Vector2 (position.x, (Gdx.graphics.getHeight() - position.y) - height);
}
基本上,您所做的是获取每个生成的对象,并根据分辨率中 x/y 值的变化来增加/减少某些对象.离本机越远,它就越大.当检查某物在某处或将某物放在某处时,始终将其编码为所需的分辨率,但在显示它或让它与程序的其余部分交互之前通过调整大小功能运行它.
Basically what you're doing is taking every object generated and running it through something that increases/decreases depending on the change in the x/y values in your resolution. The further it is from the native, the bigger it will be. When checking of something is somewhere or putting something somewhere, always code it as your desired resolution but run it through a resize function before displaying it or letting it interact with the rest of your program.
这篇关于Android libgdx 大屏分辨率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Android libgdx 大屏分辨率


- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01