簡単な紹介: 私は、モンスターが一番上に出現し、パスを移動して、それらを削除/破壊/削除する必要があるポイントに到達するゲームを構築しています。しかし、Monster Object を削除できないようです。
for (Monster i : Monstre)
{
this.add(i); //adds monster to JPanel
if(i.monstery > 50 && i.monsterx > 50){ //check if monster have reached end point
this.remove(i); //Should remove Object from the JPanel ?
i = null; //Sets object too null
Monstre.remove(i); //Removes object from arrayList "Monstre".
}else{
//Update the monsters bounds
上記はJPanelからオブジェクトを削除し、すべて問題ないようです。しかし、私が呼び出すSystem.out.println(Monstre.size());
と、生成されるモンスターの量が増えます。モンスターの生成速度を上げると、Monstre 配列リストのモンスターの量が 9000 を超え、決して減少しないため、プログラムは最終的に遅くなり始めます。私が探しているのは、ゲームの実行中にこれらのオブジェクトを削除する方法です。