[英]Reading images from a sprite sheet Java
我想在游戲中使用精靈表,並通過研究發現了這段代碼。
BufferedImage bigImg = ImageIO.read(new File("sheet.png"));
// The above line throws an checked IOException which must be caught.
final int width = 10;
final int height = 10;
final int rows = 5;
final int cols = 5;
BufferedImage[] sprites = new BufferedImage[rows * cols];
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < cols; j++)
{
sprites[(i * cols) + j] = bigImg.getSubimage(
i * width,
j * height,
width,
height
);
}
}
我了解此代碼片段如何將精靈表轉換為數組,但是如何訪問此數組。 只是sprites[i];
?
也可以將加載的精靈綁定到OpenGL紋理
int spritename = glgentextures;
{
sprites[i];
}
提前致謝。
要訪問sheet.png中的特定圖像,可以使用sprite [rowNum * cols + colNum]。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.