Loading texture in libgdx android using file in res?

自闭症网瘾萝莉.ら 提交于 2019-12-04 23:54:09

问题


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

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

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.

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


回答1:


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

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();

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



来源:https://stackoverflow.com/questions/11133799/loading-texture-in-libgdx-android-using-file-in-res

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!