在资源使用文件载入纹理libgdx机器人? [英] Loading texture in libgdx android using file in res?

查看:132
本文介绍了在资源使用文件载入纹理libgdx机器人?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在LibGdx,纹理图像存储在资源文件夹,并使用加载以下code。

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.

有没有办法来加载从Android的映像文件RES /目录?

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的方式,你不应该接触到资源文件夹。

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

这篇关于在资源使用文件载入纹理libgdx机器人?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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