Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Libgdx texture region to texture

I want to use setFilter(TextureFilter.Linear, TextureFilter.Linear); on my image, taken from textureAtlas. when I use

TextureRegion texReg = textureAtl.findRegion("myImage");
Sprite = new Sprite(texReg);

it's works fine, but if i try

TextureRegion texReg = textureAtl.findRegion("myImage");
Texture myTexture = new Texture(texReg.getTexture());
myTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
Sprite mySprite = new Sprite(myTexture);

mySprite contains all textureAtlas images. How to set to Texture single image from textureAtlas?

like image 756
Anton Sobolev Avatar asked Oct 03 '22 01:10

Anton Sobolev


1 Answers

Your last line should be:

Sprite mySprite = new Sprite(texReg);

Texture can represent a single image or multiple images (texture atlas). When there are multiple images, each is location in its texture region. You can only apply filtering to the entire texture and therefore all the images in it. If you want to apply it only to a single image, it needs to be in a separate texture.

So here is what you were doing with your code:

// get the image for your game (or whatever) object
TextureRegion texReg = textureAtl.findRegion("myImage");
// get the texture that is the 'container' of the image you want
Texture myTexture = new Texture(texReg.getTexture());
// apply filtering to the entire texture and all the images
myTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
// set the entire texture as the image for your sprite (instead of only a single region)
Sprite mySprite = new Sprite(myTexture);
like image 85
mrzli Avatar answered Oct 13 '22 10:10

mrzli