我正在用Java开发一个游戏,使用LibGDX我想要随机地形生成。我在网上发现了一个Perlin类,并决定将它用于我的项目。Perlin噪声不生成1和-1之间的数字
我现在有一个简单的世界级以此为构造:
public World() {
Random rand = new Random();
seed = rand.nextInt();
Perlin perlin = new Perlin(seed);
for(int x = 0; x < map.length; x++) {
for(int y = 0; y < map.length; y++) {
map[x][y] = perlin.noise2(x, y);
}
}
}
(地图是一个二维int数组ofcourse)
在我的游戏的主要类我创建了一个世界,然后画它在render()
方法是这样的:
batch.begin();
for (int x = 0; x < w.getMap().length; x++) {
for (int y = 0; y < w.getMap().length; y++) {
if (w.getMap()[x][y] <= 0) {
batch.draw(water, x * 32, y * 32);
}
if (w.getMap()[x][y] > 0) {
batch.draw(grass, x * 32, y * 32);
} else {
log.severe("not between -1 and 1");
}
}
}
batch.end();
一旦执行它基本上Spas控制台与“不是吐温-1和1“,并在一段时间后屏幕充满了水的质感。
这是课程还是我搞乱了?可能是后者。我应该如何解决它?另外,有关优化的任何提示?代码有点看起来凌乱。
This is the class I'm using. Posted it on pastebin because it's ~580 lines long.
更新:我固定的日志垃圾邮件,这是一种愚蠢的错误,盗贼指出。
现在我面临一个不同的问题。它似乎只是在生成水。我检查了什么getMap()[x][y]
正在返回,它基本上只有0.0s和-0.0s。
你不想让第二个“if”成为“其他”吗?这将摆脱对其他人和垃圾邮件日志的需求,因为那样的情况将不可能实现。 – alzee