使用 LWJGL 和 Slick2d,如何加载大图像(精灵表)并将其存储为较小的图像?
我已经做了一些基本的事情,我可以在屏幕上均匀地平铺草块,我可以在屏幕上显示透明纹理,但我似乎找不到任何有关从较大的精灵表加载精灵的文档。
我如何将图像分割成更小的图像?或者有不同的方法吗?
I have done a little bit of basic stuff, I can tiles a grass tile across the screen evenly, I can display a transparent texture to the screen but I can't seem to find any documentation on loading sprites from a larger sprite sheet.
How would I dice the image up into smaller images? Or is there a different way to do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Slick 中有一个 SpriteSheet 类 正是这样做的。
Slick 中的 SpriteSheets 是由一系列大小均匀的图块组成的大图像。每个图块通常是 Sprite 中的一个动画帧。在
SpriteSheet
构造函数中,您可以指定图像(包含所有图块)、工作表中图块的宽度/高度,以及任何间距和边距(如果有/需要的话)。最后,
getSprite(x, y)
方法允许您检索指定的图块,就好像它是 2D 数组中的元素一样。换句话说,如果您有一个包含 16 个图块的SpriteSheet
,这些图块排列在 4x4 的图块网格中,那么要获取第 3 列第 2 行中的图块,您可以调用getSprite( 3, 2);
我相信
getSprite(x, y)
中的索引是从零开始的,就像 Java 中的数组一样。There is a SpriteSheet class in Slick that does exactly this.
SpriteSheets, in Slick, are large images made up of a series of uniformly sized tiles. Each tile is typically an animation frame in a Sprite. In the
SpriteSheet
constructor you specify the image (which has all the tiles), and the width/height of the tiles in the sheet, along with any spacing and margin, if you have/need that.Finally, the
getSprite(x, y)
method allows you to retrieve the specified tile, as if it were an element in a 2D array. In other words, if you have aSpriteSheet
of 16 tiles, that are arranged in a 4x4 grid of tiles, then to get the tile in column 3, row 2, you would callgetSprite(3, 2);
I believe the indexes in
getSprite(x, y)
are zero-based, just like arrays in Java.