使用 LWJGL 和 Slick2d,如何加载大图像(精灵表)并将其存储为较小的图像?

发布于 2024-12-21 23:04:49 字数 109 浏览 4 评论 0原文

我已经做了一些基本的事情,我可以在屏幕上均匀地平铺草块,我可以在屏幕上显示透明纹理,但我似乎找不到任何有关从较大的精灵表加载精灵的文档。

我如何将图像分割成更小的图像?或者有不同的方法吗?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

驱逐舰岛风号 2024-12-28 23:04:49

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 a SpriteSheet of 16 tiles, that are arranged in a 4x4 grid of tiles, then to get the tile in column 3, row 2, you would call getSprite(3, 2);

I believe the indexes in getSprite(x, y) are zero-based, just like arrays in Java.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文