Java - 如何使图像代表游戏中要绘制的图块?
我试图弄清楚如何让我的游戏使用图像来代表每个点,在特定点绘制特定的图块。因此,如果该图像的一个像素是红色,则将在游戏中绘制指定的图片(图块),并且每个绿色像素代表不同的指定图像。我见过制作游戏的人这样做,但我不知道怎么做,也不知道它的名字。
如果您需要更多信息,我可以尝试解释我想做的更多事情。有人可以帮忙吗?
I am trying to figure out how to make my game draw a certain tile in a specific spot using an image to represent each spot. So if a pixel of that image was the color red a specified picture(tile) would be draw in the game, and each pixel that was green stood for a different specified image. I have seen people who make games do this but I dont know how to do it and I dont know the name for it.
If you need more info I can try to explain what I want to do more. Could someone please help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从长远来看,这实际上可能会更慢。我绝对建议您使用字节数组来表示图块,即字节[宽度][高度]。如果单个字节不再提供足够的信息,它将更快、更容易管理并且更容易扩展到 spriteData[宽度][高度] 之类的东西。
但是,如果您坚持使用图像来存储游戏数据,则可以使用类似以下内容的内容:
每个组件都在 (0...255) 范围内,您可以使用它来确定正确的图块,即
或者,您可以完全跳过提取组件,而只需使用颜色,即
(无论如何,这会稍微快一点,实际上是您想要的。)
That may actually be slower in the long run. I would definitely recommend you use a byte array to represent the tiles, i.e. byte[width][height]. It will be faster, easier to manage and easier to extend to something like spriteData[width][height] if a single byte does not supply enough information anymore.
However, if you insist on using an image to store game data, you can use something like the following:
Each component will be in the range (0...255) and you can use that to determine the correct tile, i.e.
Alternatively, you can skip extracting the components altogether, and simply use colour, i.e.
(Which will be slightly faster anyway and actually what you want.)