2015-04-04 59 views

回答

15
Texture texture = textureRegion.getTexture(); 
if (!texture.getTextureData().isPrepared()) { 
    texture.getTextureData().prepare(); 
} 
Pixmap pixmap = texture.getTextureData().consumePixmap(); 

如果只想纹理(区)的一部分,那么你就必须做一些手工加工:

for (int x = 0; x < textureRegion.getRegionWidth(); x++) { 
    for (int y = 0; y < textureRegion.getRegionHeight(); y++) { 
     int colorInt = pixmap.getPixel(textureRegion.getRegionX() + x, textureRegion.getRegionY() + y); 
     // you could now draw that color at (x, y) of another pixmap of the size (regionWidth, regionHeight) 
    } 
} 
+0

感谢,但据我所知'textureRegion.getTexture()'会返回整个textrure(图集)? – 2015-04-04 22:18:09

+3

是的,它确实如此。没有其他办法,因为只有一个纹理(这是一个地图集的全部要点)。您将不得不创建自己的较小的像素图并复制区域的部分。 – noone 2015-04-04 22:30:19

+0

我已经添加了一个小的代码片段(未经测试),你可以做到这一点。 – noone 2015-04-04 22:34:20