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 大屏分辨率
基础教程推荐
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01