Removed off screen bullets that was causing lag
This commit is contained in:
@@ -178,8 +178,13 @@ function draw() {
|
|||||||
|
|
||||||
bullets.forEach(myBullet => {
|
bullets.forEach(myBullet => {
|
||||||
//zolang mybullet bestaat blijft hij drawen en updaten
|
//zolang mybullet bestaat blijft hij drawen en updaten
|
||||||
({ hit, shot } = myBullet.update(playerPosX, playerPosY));
|
({ hit, shot, isOffScreen } = myBullet.update(playerPosX, playerPosY));
|
||||||
myBullet.draw();
|
myBullet.draw();
|
||||||
|
|
||||||
|
if (isOffScreen == true) {
|
||||||
|
myBullet.hit = true;
|
||||||
|
shot = false;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
//blijf de bullet tekenen zolang hit false is
|
//blijf de bullet tekenen zolang hit false is
|
||||||
bullets = bullets.filter(bullet => !bullet.hit);
|
bullets = bullets.filter(bullet => !bullet.hit);
|
||||||
|
@@ -45,7 +45,9 @@ class bullet {
|
|||||||
} else if (this.projectile.x < 0 - 10 || this.projectile.x > width + 10 || this.projectile.y < 0 - 10 || this.projectile.y > height + 10) {
|
} else if (this.projectile.x < 0 - 10 || this.projectile.x > width + 10 || this.projectile.y < 0 - 10 || this.projectile.y > height + 10) {
|
||||||
shot = false;
|
shot = false;
|
||||||
}
|
}
|
||||||
|
let isOffScreen = this.projectile.x < 0 || this.projectile.x > width || this.projectile.y < 0 || this.projectile.y > height;
|
||||||
|
|
||||||
return { hit, shot };
|
|
||||||
|
return { hit, shot, isOffScreen};
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user