Pavan Kumar
Pavan Kumar

Reputation: 1891

Loading texture in libgdx android using file in res?

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?

Upvotes: 5

Views: 4593

Answers (1)

Matsemann
Matsemann

Reputation: 21784

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.

Upvotes: 9

Related Questions