支持libgdx的多图像分辨率 [英] Supporting Multiple image resolution for libgdx

查看:106
本文介绍了支持libgdx的多图像分辨率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应该如何遵循目录结构以及要指定的内容,以便assetManger将使用该文件夹以实现不同的分辨率.

How should I follow the directory structure and what to specify so that assetManger will use that folder for different resolution.

我已经研究过assetManagerResolutionFileResolver,但是直到现在我还不能确切地知道如何指定文件夹以支持不同的分辨率.

I have studied assetManager and ResolutionFileResolver but until now I couldn't exactly figured how to specify the folder to support different resolutions.

推荐答案

更新:较新版本的Libgdx使用不同的策略来解析文件名(使用目录,而不是文件),因此此答案不正确适用于(0.9.2之后的新Libgdx版本吗? https://github.com/libgdx /libgdx/commit/3afcfe49c40196765033a90b4610159183dde981 )

Update: Newer versions of Libgdx use a different strategy to resolve filenames (with directories, not files), so this answer does not apply to newer Libgdx versions after (0.9.2, I think? https://github.com/libgdx/libgdx/commit/3afcfe49c40196765033a90b4610159183dde981)

内置 ResolutionFileResolver 不使用目录层次结构.它使用文件后缀将屏幕分辨率与素材资源相匹配.

The built-in ResolutionFileResolver does not use a directory hierarchy. It uses file suffixes to match screen resolutions to assets.

以下是libGDX中的代码 AssetManagerTest :

Here's the code from the libGDX AssetManagerTest:

Resolution[] resolutions = { new Resolution(320, 480, ".320480"),
                             new Resolution(480, 800, ".480800"),
                             new Resolution(480, 856, ".480854") };
ResolutionFileResolver resolver = new ResolutionFileResolver(new InternalFileHandleResolver(), resolutions);
AssetManager manager = new AssetManager();
manager.setLoader(Texture.class, new TextureLoader(resolver));
...

解析器根据当前屏幕分辨率附加这些后缀之一.因此,例如,如果您在480x800设备上查找"foo.jpg",则将打开文件"foo.jpg.480800".

The resolver appends one of those suffixes based on the current screen resolution. So, for example, if you look up "foo.jpg" on a 480x800 device, the file "foo.jpg.480800" will be opened.

如果要基于目录解析文件(因此"foo.jpg"将解析为"480x800/foo.jpg"或类似名称),则可以编写新的解析器.只需实现 FileHandleResolver . ResolutionFileResolver. java 源可能是一个很好的起点.

If you want to resolve files based on directories (so "foo.jpg" would be resolved to "480x800/foo.jpg" or something like that), you can write a new resolver. Just implement FileHandleResolver. The ResolutionFileResolver.java source is probably a good place to start.

这篇关于支持libgdx的多图像分辨率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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