Java 从sprite工作表读取图像
我想在我的游戏中使用精灵表,通过研究我发现了这段代码Java 从sprite工作表读取图像,java,lwjgl,Java,Lwjgl,我想在我的游戏中使用精灵表,通过研究我发现了这段代码 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 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
);
}
}
提前谢谢。要访问sheet.png中的某个图像,可以使用sprite[rowNum*cols+colNum]。谢谢,我可以在glgentextures中使用这个调用吗?好的,我尝试了多种方法,但无法使其工作,任何人都可以获得一些代码,我可以阅读并学习如何正确操作,所以我有一些关于如何做的线索。你试过TextureIO.newTexture(sprite[I],false)吗?另外,请注意精灵的尺寸,因为此代码仅适用于拆分为25个10x10px图像的图像。
int spritename = glgentextures;
{
sprites[i];
}