Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LibGDX: Filtering a scaled TextureRegion

I have several objects with different textures for different states, so I am using a TextureAtlas made with TexturePacker, and resizing the TextureRegion where I need it. I have to resize because not only am I trying to support both 720p and 1080p, but some of my objects are tiles or cursors which resize based on the width and height of the board, as that can change in my game whereas the board will always occupy the same percentage of the screen.

With a Texture, I can just do this:

texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);

However, when I am using a TextureRegion there is no option to set a filter. This results in these TextureRegions resizing as sharp, blocky, and jagged. It isn't nice scaling and it doesn't seem to anti-alias at all.

This is pretty frustrating, because I'm bad enough at making graphics and now even when I like what I've made it looks crappy. What do I do to replicate the effect of TextureFilter.Linear using a TextureRegion instead of a Texture?

like image 505
Mike Carpenter Avatar asked Jul 15 '13 22:07

Mike Carpenter


1 Answers

You can open your .atlas file and change the filter value to Linear, Linear. Or you can use region.getTexture() to get access to the Texture to which the region belongs, then call setFilter(...) on that.

like image 184
nEx.Software Avatar answered Oct 13 '22 01:10

nEx.Software