LibGDX: Filtering a scaled TextureRegion

北城余情 提交于 2019-12-30 08:25:36

问题


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?


回答1:


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.




回答2:


If you are packing using gdx-tools then you have to set the option

Settings settings = new Settings();
    settings.paddingX = 2;
    settings.paddingY = 2;
    settings.minWidth = 32;
    settings.minHeight = 32;
    settings.maxHeight = 1024;
    settings.maxWidth = 1024;
    settings.stripWhitespaceX = true;
    settings.stripWhitespaceY = true;
    settings.filterMag = TextureFilter.Nearest;
    settings.filterMin = TextureFilter.Nearest;
    settings.flattenPaths = true;

     TexturePacker2.process(settings, "input directory", "output directory","packName");

    System.out.println("PackTextures->main finished.");

or if you are using texture-packer-gui.jar then tick the checkbox for linear(min) and linear(max) and you are good to go...



来源:https://stackoverflow.com/questions/17664924/libgdx-filtering-a-scaled-textureregion

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