0

我想在我的游戏中使用精灵表,并且通过我所做的研究发现了这段代码。

    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];
}

提前致谢。

4

1 回答 1

1

要访问 sheet.png 中的某个图像,您可以使用 sprite[rowNum*cols + colNum]。

于 2012-05-15T16:27:25.970 回答