我有一个click事件,它检查是否应删除(isSquashed)数组中的对象,当它为true时,我们将从数组列表中删除该对象,但是当这种情况到来时,我要么需要退出循环,要么递减i值,基本上我想从for循环中退出,并在拼接数组对象后使用newArray列表长度再次调用gameloop。
我尝试过两种方式1.向后迭代for循环2.给出中断声明(获取非法中断声明)但对我来说仍然没有发生,所以有人可以帮我解决这个问题,让我知道如何解决这个问题,
maingameloop =函数(antsArray){
//inititialization // antsArray[i].draw(); // antsArray[i].checkifSmashed(); //gameloop if (this.isplaying) { console.log(this.score); for (let i = 0 ; i < antsArray.length; i++) { let gameloop = setInterval(() => { antsArray[i].move(); antsArray[i].update(antsArray); if (antsArray[i].isSquashed) { this.score++; antsArray.splice(i, 1); // i--; clearInterval(gameloop); // this.isplaying = false ; } , this.FRAME_RATE); }}else { //gameover // this.maingameloop(antsArray); } }
当我从数组中删除对象时,得到的结果是:Uncaught TypeError:无法读取未定义的属性“ move”
我有一个click事件,它检查是否应删除数组中的对象(已压缩),当它为true时,我们将从数组列表中删除该对象,但是当出现这种情况时,我要么需要...
循环间隔或超时永远不是一个好主意