mirror of
https://github.com/wassname/phaser.git
synced 2026-07-05 17:30:19 +08:00
getBounds update.
This commit is contained in:
@@ -18,7 +18,7 @@ Phaser.AnimationManager = function (parent) {
|
||||
this._frameData = null;
|
||||
|
||||
/**
|
||||
* Keeps track of the current frame of animation.
|
||||
* Keeps track of the current frame of the animation.
|
||||
*/
|
||||
this.currentFrame = null;
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ Phaser.Animation.Frame = function (x, y, width, height, name, uuid) {
|
||||
this.height = height;
|
||||
this.name = name;
|
||||
this.uuid = uuid;
|
||||
this.distance = Phaser.Math.distance(0, 0, width, height);
|
||||
|
||||
};
|
||||
|
||||
@@ -50,6 +51,12 @@ Phaser.Animation.Frame.prototype = {
|
||||
*/
|
||||
height: 0,
|
||||
|
||||
/**
|
||||
* The distance from the top left to the bottom-right of this Frame.
|
||||
* @type {number}
|
||||
*/
|
||||
distance: 0,
|
||||
|
||||
/**
|
||||
* Useful for Sprite Sheets.
|
||||
* @type {number}
|
||||
|
||||
@@ -108,17 +108,21 @@ Phaser.Sprite = function (game, x, y, key, frame) {
|
||||
|
||||
// Edge points
|
||||
this.offset = new Phaser.Point();
|
||||
this.center = new Phaser.Point();
|
||||
this.topLeft = new Phaser.Point();
|
||||
this.topRight = new Phaser.Point();
|
||||
this.bottomRight = new Phaser.Point();
|
||||
this.bottomLeft = new Phaser.Point();
|
||||
|
||||
// Do we need all 4 edge points? It might be better to just calculate the center and apply the circle for a bounds check
|
||||
this.getLocalPosition(this.center, this.offset.x + this.width / 2, this.offset.y + this.height / 2);
|
||||
this.getLocalPosition(this.topLeft, this.offset.x, this.offset.y);
|
||||
this.getLocalPosition(this.topRight, this.offset.x + this.width, this.offset.y);
|
||||
this.getLocalPosition(this.bottomLeft, this.offset.x, this.offset.y + this.height);
|
||||
this.getLocalPosition(this.bottomRight, this.offset.x + this.width, this.offset.y + this.height);
|
||||
|
||||
this.bounds = new Phaser.Rectangle(x, y, this.width, this.height);
|
||||
|
||||
this._dirty = false;
|
||||
|
||||
// transform cache
|
||||
@@ -200,13 +204,17 @@ Phaser.Sprite.prototype.update = function() {
|
||||
this.offset.setTo(this._a02 - (this.anchor.x * this._sw), this._a12 - (this.anchor.y * this._sh));
|
||||
|
||||
// Do we need all 4 edge points? It might be better to just calculate the center and apply the circle for a bounds check
|
||||
this.getLocalPosition(this.center, this.offset.x + this.width / 2, this.offset.y + this.height / 2);
|
||||
this.getLocalPosition(this.topLeft, this.offset.x, this.offset.y);
|
||||
this.getLocalPosition(this.topRight, this.offset.x + this._sw, this.offset.y);
|
||||
this.getLocalPosition(this.bottomLeft, this.offset.x, this.offset.y + this._sh);
|
||||
this.getLocalPosition(this.bottomRight, this.offset.x + this._sw, this.offset.y + this._sh);
|
||||
|
||||
// Update our bounds
|
||||
this.getBounds(this.bounds);
|
||||
}
|
||||
|
||||
// this.checkBounds();
|
||||
// Check our bounds
|
||||
|
||||
}
|
||||
|
||||
@@ -215,6 +223,8 @@ Phaser.Sprite.prototype.getLocalPosition = function(p, x, y) {
|
||||
p.x = ((this._a11 * this._id * x + -this._a01 * this._id * y + (this._a12 * this._a01 - this._a02 * this._a11) * this._id) * this._sx) + this._a02;
|
||||
p.y = ((this._a00 * this._id * y + -this._a10 * this._id * x + (-this._a12 * this._a00 + this._a02 * this._a10) * this._id) * this._sy) + this._a12;
|
||||
|
||||
// At this point could be working out the smallest / largest value for the bounds check
|
||||
|
||||
return p;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user