Don't render offscreen lights

This commit is contained in:
2014-06-11 20:12:13 -07:00
parent accb1922e2
commit 78e1eb4210

View File

@@ -154,6 +154,8 @@ var Torch = function(game, x, y, radius, fade, color) {
this.color = color; this.color = color;
this.radius = radius; this.radius = radius;
this.fade = radius * fade this.fade = radius * fade
this.rect = new Phaser.Rectangle(this.x, this.y, radius * 2, radius * 2)
}; };
// Torches are a type of Phaser.Sprite // Torches are a type of Phaser.Sprite
@@ -269,11 +271,11 @@ GameState.prototype.updateShadowTexture = function() {
// Iterate through each of the lights and draw the glow // Iterate through each of the lights and draw the glow
this.staticLights.forEach(function(light) { this.staticLights.forEach(function(light) {
var intersects = light.intersectsRaw(this.game.camera.x, var r1 = new Phaser.Rectangle(this.game.camera.x,
this.game.camera.x + this.game.camera.width, this.game.camera.y,
this.game.camera.y, this.game.camera.width,
this.game.camera.y + this.game.camera.height); this.game.camera.height);
if ( ! intersects ) { if ( ! light.rect.intersects(r1) ) {
return; return;
} }
// Randomly change the radius each frame // Randomly change the radius each frame