无法在数组类型 int[][] 上调用 splice(int, int)

Cannot invoke splice(int, int) on the array type int[][]

我有一个我似乎无法理解的简短代码。我遇到的最大问题是我不理解错误并且似乎无法找到如何更改数组类型的方法。

int [][] spawnLocatiesCoins = new int [20][2];


void collectenVanCoins () {
  if (gameState == 1) {
    for (int i = 0; i<10; i++) {
      if (key == 's' && dist(spawnLocatiesCoins[i][0], spawnLocatiesCoins[i][1], xPosPlayer1, yPosPlayer1) < 20) {
        println("catch" + i);
        score++;
        spawnLocatiesCoins.splice(i, 1);
      }
    }
  }
}

尝试做的是从我的数组中删除spawnLocationsCoins[i]。我在这里得到的错误消息是 Cannot invoke splice(int, int) on the array type int[][]。我已经尝试了几种不同的拼接方法。我也尝试过使用 remove 方法但没有结果。

有人可以向我解释如何从 int [][] 数组中删除一个项目。

您可能正在尝试使用 Processing splice 函数,但是,这并不能满足您的要求 ("Inserts a value or an array of values into an existing array")。

我会说你最好使用这样的 ArrayList instead of an array, where you can then just use the .remove 函数:

list.remove(index);

因为你想存储 2 个值(x 和 y),你可以创建一个 int 数组的 ArrayList

ArrayList<int[]> spawnLocatiesCoins = new ArrayList<int[]>();

您可以像这样添加值:

spawnLocatiesCoins.add(new int[]{x_value, y_value});

并像这样访问它们:

spawnLocatiesCoins.get(index)[index_in_the_array];

您也可以使用 PVectors(可以存储 2/3 值的变量(取决于您是否正在制作 3D 程序))而不是数组,但此时您可能不需要它们.