java - Libgdx 纹理区域到纹理

标签 java textures 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 single image?

最佳答案

你的最后一行应该是:

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

关于java - Libgdx 纹理区域到纹理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20786635/

相关文章:

java - 如何从给定日期生成 N 周数 - java

c++ - glGetTexImage 读取过多纹理格式为 GL_ALPHA 的数据

opengl - 纹理数组大小的限制是什么?

android - LibGDX - 限制透视相机的缩放

java - Libgdx 获取缩放的触摸位置

java - 在 Java 中访问类内部实例变量的最佳方法是什么?

java - 如何统计每个单词出现的次数?

android - LibGDX 表内的 LinearLayout 模拟

java - 如何在我创建的目录中创建文本文件(Android外部存储)

android - 有没有办法在 Android 上使用 OpenGL 在两个上下文/线程之间共享纹理?