编程语言
首页 > 编程语言> > java-Libgdx纹理区域进行纹理处理

java-Libgdx纹理区域进行纹理处理

作者:互联网

我想使用setFilter(TextureFilter.Linear,TextureFilter.Linear);在我的图像上,取自textureAtlas.当我使用

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

很好,但是如果我尝试

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

mySprite包含所有textureAtlas图像.如何从textureAtlas设置为Texture单张图像?

解决方法:

您的最后一行应该是:

Sprite mySprite = new Sprite(texReg);

纹理可以表示单个图像或多个图像(纹理图集).当有多个图像时,每个图像都位于其纹理区域中.您只能将过滤应用于整个纹理,因此也只能应用于其中的所有图像.如果只想将其应用于单个图像,则需要使用单独的纹理.

所以这是您对代码的处理方式:

// 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);

标签:libgdx,textures,java
来源: https://codeday.me/bug/20191030/1964823.html