【发布时间】:2017-10-26 21:57:08
【问题描述】:
我正在尝试将我的纹理区域制作成像素图,但是通过遵循准备好的方法,它将整个图集复制到像素图中,因此建议我循环每个像素并手动将其映射到另一个像素图中
Pixmap emptyPixmap = new Pixmap(trLine.getRegionWidth(), trLine.getRegionHeight(), Pixmap.Format.RGBA8888);
Texture texture = trLine.getTexture();
texture.getTextureData().prepare();
Pixmap pixmap = texture.getTextureData().consumePixmap();
for (int x = 0; x < trLine.getRegionWidth(); x++) {
for (int y = 0; y < trLine.getRegionHeight(); y++) {
int colorInt = pixmap.getPixel(trLine.getRegionX() + x, trLine.getRegionY() + y);
emptyPixmap.drawPixel( trLine.getRegionX() + x , trLine.getRegionY() + y , colorInt );
}
}
trBlendedLine=new Texture(emptyPixmap);
但是生成的纹理没有绘制任何内容,这意味着 getPixel 没有获得正确的像素。请指教。
【问题讨论】:
-
方法 trLine.getTexture() 获取纹理区域的整个纹理。如果您只想要特定区域,请使用 trLine
-
你试过这个解决方案了吗:stackoverflow.com/questions/29451787/…
-
@MilanG 是的,我正在尝试这个解决方案,但无法让它与 textureRegion 一起使用
-
@dfour 感谢您的信息,但我需要使用 consumePixmap() 方法将纹理区域映射到像素图