libGDX:较小分辨率时缩放纹理 [英] libGDX: Scale Textures when smaller resolution

查看:83
本文介绍了libGDX:较小分辨率时缩放纹理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了一些有关视口的文章,以解决不同分辨率的问题.但是在每个示例中,它们使用的纹理尺寸都小于屏幕的分辨率.但是,当我的纹理大小为1920 x 1080,而屏幕仅为800 x 400时,会发生什么呢?是否有任何可以缩放纹理的视口?我没有发现任何有关此问题的信息.

解决方案

看起来像是在缩放而不是压缩.压缩是一种减小文件文件大小的技术,就像 .jpg 会覆盖未压缩的 .bmp 一样.因此,如果您要进行缩放,那么它完全取决于您的需求.如果您具有1920x1080的纹理,并希望它完全适合800x400的屏幕,则需要拉伸它,因为 1920x1080 = 16x9 800x400 = 2:1 = 16:8 .

要拉伸图像,您需要使用 StretchViewport .您将使用要显示的世界尺寸创建视口.因此,在这种情况下,将1920x1080图像或16x9图像放置在您的世界中,并在其中放置世界单位". StretchViewport 将确保视口被拉伸到您使用的任何大小.

如果您希望它尽可能适合但仍保持16:9的纵横比,则可以使用 FitViewport .像 StretchViewport 一样,每个视口( ScreenViewport 除外)都需要提供世界单位,这是一个重要的概念.除非您如此定义世界单位,否则世界单位不是米或像素.无论如何, FitViewport 还将确保每台设备在提供时都能看到您的世界,但资产不会拉伸/变形.相反,它将创建一个黑色"条,就像长宽比不相等时的电视一样.

ScreenViewport,默认只占用屏幕的大小.因此1920x1080像素的屏幕将显示1920x1080的世界单位,而640x480像素的屏幕将显示640x480的世界单位.因此,屏幕分辨率越高,可见的世界越多.屏幕像素代表的世界单位数量可以更改.

还有其他视图: FillViewport 就像 FitViewport 一样,它将保持宽高比,但始终会填满整个屏幕.因此,某些部分可能不可见.因此,我无法在 FitViewport 上使用它.还有 ExtentVieport ,是 FitViewport ScreenViewport 之间的混合.

I've read some articles about Viewports to solve the problem with different resolution. But in every example they used a smaller size for the texture than the resolution of the screen. But what happens when my texture size is for example 1920 x 1080 and my screen is just 800 x 400? Is there any kind of Viewport that can scale the texture? I didn't found anything for this problem.

解决方案

Looks like you mean scaling and not compressing. Compressing is a technique to lower the file size of a file, like a .jpg does over a uncompressed .bmp. So if you mean scaling then it completely depends on what you want. If you have a 1920x1080 texture and want this to completely fit the 800x400 screen it needs to be stretched since 1920x1080 = 16x9 and 800x400 = 2:1 = 16:8.

To stretch the image you need to use StretchViewport. You would create the viewport with the world dimensions you want to show. So in this case the 1920x1080 image, or perhaps 16x9 and put that texture with there "world units) in your world. StretchViewport will make sure the viewport is stretched to whatever size you use.

If you want it to fit as much as possible but remain the aspect ratio of 16:9 then you can use the FitViewport. Like StretchViewport each viewport (except ScreenViewport) need to be supplied with world units, this is a important concept. World units are not meters nor pixels until you define your world units as such. Anyway, FitViewport will also make sure each device sees as much of your world as you supply it but your assets won't stretch/deform. Instead it will create a "black" bar, much like TV's do when the aspect ratio is not equal.

ScreenViewport, by default just takes the size of the screen. So a 1920x1080 pixel screen would show 1920x1080 world units and a 640x480 pixel screen would show 640x480 world units. Therefore, the higher resolution the screen has the more of the world is visible. The amount of world units a screen pixel represents can be changed.

There are a view others: FillViewport is like FitViewport it will remain aspect ratio but always fills the screen. And thus some parts may not be visible. For that reason I can't think of a use for this one over FitViewport. And there is ExtentVieport, a mix between FitViewport and ScreenViewport.

这篇关于libGDX:较小分辨率时缩放纹理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆