Removed off screen bullets that was causing lag

This commit is contained in:
Sam
2023-11-30 22:38:17 +01:00
parent e98ce2415d
commit 78c95b29f7
2 changed files with 9 additions and 2 deletions

View File

@@ -178,8 +178,13 @@ function draw() {
bullets.forEach(myBullet => {
//zolang mybullet bestaat blijft hij drawen en updaten
({ hit, shot } = myBullet.update(playerPosX, playerPosY));
({ hit, shot, isOffScreen } = myBullet.update(playerPosX, playerPosY));
myBullet.draw();
if (isOffScreen == true) {
myBullet.hit = true;
shot = false;
}
});
//blijf de bullet tekenen zolang hit false is
bullets = bullets.filter(bullet => !bullet.hit);

View File

@@ -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) {
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};
}
}