Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading texture in libgdx android using file in res?

Tags:

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

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?

like image 301
Pavan Kumar Avatar asked Jun 21 '12 07:06

Pavan Kumar


1 Answers

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.

like image 126
Matsemann Avatar answered Sep 21 '22 13:09

Matsemann