繁体   English   中英

Libgdx纹理区域到纹理

[英]Libgdx texture region to texture

我想使用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设置纹理单个图像?

你的最后一行应该是:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM