Work around Phaser issue #926, rectangle negative height/width values

This commit is contained in:
2014-06-18 09:34:14 -07:00
parent 134c6e8e29
commit 7d344c2a21

View File

@@ -68,7 +68,7 @@ var Light = function(game, x, y, key, frame, radius, fade, color_start, color_st
this.fade = radius * fade this.fade = radius * fade
this.light_meter = light_meter; this.light_meter = light_meter;
this.always_render = always_render this.always_render = always_render
this.rect = new Phaser.Rectangle(this.x - radius, this.y - radius, radius * 2, radius * 2) this.rect = positiveRectangle(this.x - radius, this.y - radius, radius * 2, radius * 2)
this.flicker = flicker; this.flicker = flicker;
}; };
@@ -82,7 +82,7 @@ Light.prototype.update_new_values = function() {
this.fade = this.radius * Number(this.fade); this.fade = this.radius * Number(this.fade);
this.flicker = parseBoolean(this.flicker); this.flicker = parseBoolean(this.flicker);
this.always_render = parseBoolean(this.always_render); this.always_render = parseBoolean(this.always_render);
this.rect = new Phaser.Rectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2) this.rect = positiveRectangle(this.x - this.radius, this.y - this.radius, this.radius * 2, this.radius * 2)
} }
function SoundSprite(game, x, y, key, frame, function SoundSprite(game, x, y, key, frame,
@@ -706,10 +706,10 @@ var AISprite = function(game, x, y, key, frame) {
offset = [offset[0] * 2, offset[1] * 2]; offset = [offset[0] * 2, offset[1] * 2];
size = [size[0] * 2, size[1] * 2]; size = [size[0] * 2, size[1] * 2];
} }
return new Phaser.Rectangle(this.x + offset[0], return positiveRectangle(this.x + offset[0],
this.y + offset[1], this.y + offset[1],
size[0], size[0],
size[1]); size[1]);
} }
this.canSeeSprite = function(spr, debug) { this.canSeeSprite = function(spr, debug) {
@@ -735,7 +735,7 @@ var AISprite = function(game, x, y, key, frame) {
console.log("I don't have a view rectangle"); console.log("I don't have a view rectangle");
return false; return false;
} }
var sprrect = new Phaser.Rectangle(spr.x, spr.y, 32, 32); var sprrect = positiveRectangle(spr.x, spr.y, 32, 32);
if ( viewrect.intersects(sprrect) || viewrect.containsRect(sprrect) ) { if ( viewrect.intersects(sprrect) || viewrect.containsRect(sprrect) ) {
return true; return true;
} }
@@ -1202,6 +1202,18 @@ function rotatePoints(arr, x, y, degrees)
}, this); }, this);
} }
function positiveRectangle(x, y, w, h) {
if ( w < 0 ) {
w = -(w);
x = x - w;
}
if ( h < 0 ) {
h = -(h);
y = y - h;
}
return new Phaser.Rectangle(x, y, w, h);
}
function addAnimation(obj, anim) function addAnimation(obj, anim)
{ {
a = moonlightSettings['animations'][anim] a = moonlightSettings['animations'][anim]
@@ -1332,10 +1344,10 @@ GameState.prototype.create = function()
0, 0,
this.uigroup); this.uigroup);
this.lightbar_image = game.cache.getImage('lightbar'); this.lightbar_image = game.cache.getImage('lightbar');
this.lightbar_crop = new Phaser.Rectangle(0, this.lightbar_crop = positiveRectangle(0,
0, 0,
this.lightbar_image.width, this.lightbar_image.width,
this.lightbar_image.height); this.lightbar_image.height);
this.uigroup.setAll('fixedToCamera', true); this.uigroup.setAll('fixedToCamera', true);
} }
@@ -1345,10 +1357,10 @@ GameState.prototype.updateShadowTexture = function() {
this.staticLights.forEach(function(light) { this.staticLights.forEach(function(light) {
if ( light.always_render !== true ) { if ( light.always_render !== true ) {
var r1 = new Phaser.Rectangle(this.game.camera.x, var r1 = positiveRectangle(this.game.camera.x,
this.game.camera.y, this.game.camera.y,
this.game.camera.width, this.game.camera.width,
this.game.camera.height); this.game.camera.height);
if ( ! light.rect.intersects(r1) ) { if ( ! light.rect.intersects(r1) ) {
return; return;
} }