Android libgdx 大屏幕分辨率
我如何支持(制定算法)libgdx以支持多种屏幕分辨率?我使用 if 语句使我的应用程序在 HTC Tattoo 上运行,参数如下:
if (Gdx.input.getX()==40) {
在更大的屏幕上运行该应用程序的好算法是什么? 我尝试了这个,但没有任何结果:
publis static int translatex() {
float p = (float)Gdx.graphics.getHeight()*340;
return (int) p*Gdx.input.getX();
}
340 是我在 HTC Tattoo 上使用的基本 x(我手机上的 x 分辨率)。 那么......我怎样才能制作一个支持绝对值大屏幕的函数。我不想改变 if 语句。
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 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这很容易。您基本上是根据原始分辨率构建整个程序,但是在处理定位和纹理大小的所有内容中都有这样的事情:
基本上您正在做的就是获取生成的每个对象并通过根据变化而增加/减少的东西来运行它分辨率中的 x/y 值。距离本地越远,它就越大。当检查某处的某物或将某物放置在某处时,始终将其编码为您想要的分辨率,但在显示它或让它与程序的其余部分交互之前通过调整大小函数运行它。
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:
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.
在 http://www.java-gaming.org/index 查看更优雅的解决方案.php?topic=25685.0(另请参阅 Nate 对该解决方案的评论)。
另外,如果您使用 scene2d,请注意当前(libgdx 0.9.6)stage.setViewport 方法应该具有此功能,但它的行为并不像人们预期的那样。
更新: setViewPort 已修复,因此可以按预期工作。
See a more elegant solution at http://www.java-gaming.org/index.php?topic=25685.0 (also see Nate's comment to that solution).
Also, if you use
scene2d
, note that currently (libgdx 0.9.6)stage.setViewport
method should have this functionality, but it doesn't really behave as one would expect.Update: setViewPort was fixed, so this works just as expected.