LibGDX:过滤缩放的 TextureRegion

2022-01-12 00:00:00 game-engine textures java libgdx scaling

我有几个对象在不同的​​状态下具有不同的纹理,所以我使用了一个用 TexturePacker 制作的 TextureAtlas,并在我需要的地方调整了 TextureRegion 的大小.我必须调整大小,因为我不仅要同时支持 720p 和 1080p,而且我的一些对象是瓷砖或光标,它们会根据棋盘的宽度和高度调整大小,因为这可能会在我的游戏中改变,而棋盘总是占据屏幕的相同百分比.

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.

使用 Texture,我可以这样做:

With a Texture, I can just do this:

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

但是,当我使用 TextureRegion 时,没有设置过滤器的选项.这会导致这些 TextureRegion 的大小调整为锐利、块状和锯齿状.这不是很好的缩放,而且似乎根本没有抗锯齿.

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.

这很令人沮丧,因为我在制作图形方面已经够糟糕了,现在即使我喜欢我制作的东西,它看起来也很糟糕.如何使用 TextureRegion 而不是 Texture 来复制 TextureFilter.Linear 的效果?

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?

推荐答案

您可以打开 .atlas 文件并将 filter 值更改为 Linear, Linear.或者您可以使用 region.getTexture() 来访问该区域所属的纹理,然后在其上调用 setFilter(...).

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.

相关文章