【发布时间】:2021-08-26 16:56:12
【问题描述】:
我正在尝试制作策略游戏,但我无法从棋盘上删除敌人标记。 array.splice(index,number) 是否按数字缩短数组长度?
let map1 = [/* enemy pieces in a grid*/]
let enemyPositions = [/* numeric positions of enemy pieces*/]
// finds the value of piece\/
let attackVal = getTropperValue(pieceIndex);
let defenseVal = getTropperValue(pieceIndex+10);
// if the miner is attacking a bomb, the miner wins
if (attackVal===3 && defenseVal === 11 && facing === "down")
{
setTimeout( () => removePiece(pieceIndex+10),1000);
map1.splice(pieceIndex+10,1,"");
enemyPositions.splice(pieceIndex+10,1);
}
【问题讨论】:
-
“array.splice(index,number) 是否按数字缩短数组的长度?”答案是肯定的。但我不确定这个答案对你有什么帮助。你最好描述一下你遇到的问题。
-
"按数字缩短数组的长度" - 有点?
a = [0,1,2,3,4]; a.splice(2);将导致a成为[0,1] -
我将数组输出到控制台,但在我删除的空间中显示
-
@bebro22 请确保问题中的示例是minimal reproducible example?我们无法调试我们看不到的东西。
-
“array.splice(index,number) 做 X 吗?” — 阅读documentation。
标签: javascript arrays 2d-games