使用res中的文件在libgdx android中加载纹理?

Loading texture in libgdx android using file in res?(使用res中的文件在libgdx android中加载纹理?)

本文介绍了使用res中的文件在libgdx android中加载纹理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 LibGdx 中,纹理图像存储在资产文件夹中,并使用以下代码加载.

In LibGdx, texture image is stored in asset folder and loaded using following code.

Texture texture = new Texture(Gdx.files.internal("image/someImage.jpg"));

我对不同的屏幕分辨率有不同的纹理,所以我想使用Android的res/"目录来保存纹理图像,这有助于加载适当的图像文件以获得适当的分辨率.

I have different texture for different screen resolution, so I want to use Android "res/" directory for saving texture image, which helps to load appropriate image file for appropriate resolution.

有没有办法从Androidres/"目录加载图片文件?

Is there any way to load image file from Android "res/" directory?

推荐答案

你应该看看libgdx的ResolutionFileResolver,也可以使用AssetManager(它会为你减轻一切).

You should look into libgdx's ResolutionFileResolver, and also use AssetManager (it will ease everything for you).

您为其提供分辨率和要使用的正确文件夹,然后 libgdx 会自动选择最匹配的文件夹.

You supply it resolutions and the proper folder to use, and then libgdx automagically selects the folder with the best match.

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

这是在 libgdx 中执行此操作的方法,您不应该触摸 res 文件夹.

This is the way to do it in libgdx, you shouldn't touch the res folder.

这篇关于使用res中的文件在libgdx android中加载纹理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:使用res中的文件在libgdx android中加载纹理?

基础教程推荐