Loading texture in libgdx android using file in res?(使用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中加载纹理?


- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01