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

查看:39
本文介绍了支持 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/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天全站免登陆