Added Sprite.getBounds function

This commit is contained in:
Richard Davey
2013-09-01 11:15:13 +01:00
parent d54a92310d
commit 71b4cc532f
2 changed files with 71 additions and 0 deletions
+20
View File
@@ -219,6 +219,26 @@ Phaser.Sprite.prototype.getLocalPosition = function(p, x, y) {
}
Phaser.Sprite.prototype.getBounds = function(rect) {
rect = rect || new Phaser.Rectangle;
var left = Math.min(this.topLeft.x, this.topRight.x, this.bottomLeft.x, this.bottomRight.x);
var right = Math.max(this.topLeft.x, this.topRight.x, this.bottomLeft.x, this.bottomRight.x);
var top = Math.min(this.topLeft.y, this.topRight.y, this.bottomLeft.y, this.bottomRight.y);
var bottom = Math.max(this.topLeft.y, this.topRight.y, this.bottomLeft.y, this.bottomRight.y);
rect.x = left;
rect.y = top;
rect.width = right - left;
rect.height = bottom - top;
// This could work to include the children by running through the linked list and storing only the highest min.max values
return rect;
}
Object.defineProperty(Phaser.Sprite.prototype, 'angle', {
get: function() {