下面的代码应该用空格替换 tilemap 索引,但是没有任何反应。
瓷砖地图:
var tilemap = [
"wwwwwwwwwwwwwwww",
"wmmmmmmmmmmmmmmw",
"wmwmwmwwwwmwmwmw",
"wmmbwmmmmmmwbmmw",
"wmwwwwwwwwwwwwmw",
"wmwmmmmssmmmmwmw",
" mwmwwwsswwwmwm ",
"wmwmwwwwwwwwmwmw",
" mwmwmmmmmmwmwm ",
"wmwmwmwwwwmwmwmw",
"wmwmmmmmmmmmmwmw",
"wmwmwwwwwwwwmwmw",
"wmwmwbmmmmbwmwmw",
"wmwmwmwwwwmwmwmw",
"wmmmmmmmmmmmmmmw",
"wwwwwwwwwwwwwwww",];
更改 tilmap 的代码:
if (Player.x > j*25 &&
Player.x < j*25+25 &&
Player.y > i*25 &&
Player.y < i*25+25
) {
tilemap[i][j] = ' ';
}
奇怪的是,如果它是 tilemap[i] 甚至是 tilemap[j] 而不是 tilemap[i][j],它会做你认为它会做的事情,并且 tilemap[i][j] 用于遍历 tilemap在它所在的循环中。换句话说,这会改变瓦片地图中的整行:
if (Player.x > j*25 &&
Player.x < j*25+25 &&
Player.y > i*25 &&
Player.y < i*25+25
) {
tilemap[i] = ' ';
}