如何将这个匹配语句转换为 HashMap?
如何将这个 match
块转换为 HashMap?理想情况下,我想从清单文件创建 HashMap:
match layers[1][p] {
',' => tile = grass,
'*' => tile = sand,
// And so on....
}
我之前尝试这样做,但 Macroquad 的 Texture2D 与 HashMap 不兼容。 (我认为编译器说“不能将选项用作Texture2D”。)
我想做这样的事情:
let tile = hashmap.get(layers[p]);
blit(tile);
How could I convert this match
block into a HashMap? Ideally I would like to create a HashMap from a manifest file:
match layers[1][p] {
',' => tile = grass,
'*' => tile = sand,
// And so on....
}
I tried doing this earlier, but Macroquad's Texture2D is not compatible with a HashMap. (I think the compiler said 'Cannot use Option as Texture2D'.)
I would like to do something like this:
let tile = hashmap.get(layers[p]);
blit(tile);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
让我们保持简单。我不认为 hashmap 会简化任何东西,但为什么不演示它呢。散列的真正优点是您可以动态加载图块并使它们加载到地图中。不过现在,我们将对一些进行硬编码。
Let's keep this simple. I don't think hashmap will simplify anything but why not demonstrate it. The true advantage of hash is that you can load tiles dynamically and make them loaded into the map. For now, though, we will hardcode some.