Ant*_*lev 5 java textures libgdx
我想setFilter(TextureFilter.Linear, TextureFilter.Linear);在我的图像上使用,取自textureAtlas。当我使用
TextureRegion texReg = textureAtl.findRegion("myImage");
Sprite = new Sprite(texReg);
Run Code Online (Sandbox Code Playgroud)
它工作正常,但如果我尝试
TextureRegion texReg = textureAtl.findRegion("myImage");
Texture myTexture = new Texture(texReg.getTexture());
myTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
Sprite mySprite = new Sprite(myTexture);
Run Code Online (Sandbox Code Playgroud)
mySprite 包含所有textureAtlas 图像。如何从textureAtlas设置纹理单个图像?
你的最后一行应该是:
Sprite mySprite = new Sprite(texReg);
Run Code Online (Sandbox Code Playgroud)
纹理可以表示单个图像或多个图像(纹理图集)。当有多个图像时,每个图像都位于其纹理区域中。您只能对整个纹理以及其中的所有图像应用过滤。如果您只想将其应用于单个图像,则它需要位于单独的纹理中。
所以这就是您对代码所做的事情:
// 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);
Run Code Online (Sandbox Code Playgroud)