2015-04-04 36 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