diff --git a/src/core/display/ObservablePoint.js b/src/core/display/ObservablePoint.js index 4d65964..836fcdd 100644 --- a/src/core/display/ObservablePoint.js +++ b/src/core/display/ObservablePoint.js @@ -1,11 +1,12 @@ /** + * The Point object represents a location in a two-dimensional coordinate system, where x represents + * the horizontal axis and y represents the vertical axis. * An observable point is a point that triggers a callback when the point's position is changed. * * @class * @memberof PIXI - * - * @param cb {function} The function to be called when the point changes - * @param scope {*} The scope to be applied to the cb + * @param cb {Function} callback when changed + * @param scope {Object} owner of callback * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ @@ -37,8 +38,10 @@ }, set: function (value) { - this._x = value; - this.cb.call(this.scope); + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); + } } }, /** @@ -54,8 +57,10 @@ }, set: function (value) { - this._y = value; - this.cb.call(this.scope); + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } } } }); @@ -69,8 +74,27 @@ */ ObservablePoint.prototype.set = function (x, y) { - this._x = x || 0; - this._y = y || ( (y !== 0) ? this._x : 0 ); + var _x = x || 0; + var _y = y || ( (y !== 0) ? _x : 0 ); + if (this._x !== _x || this._y !== _y) + { + this._x = _x; + this._y = _y; + this.cb.call(this.scope); + } +}; - this.transform._versionLocal++; // TODO: Pretty sure this doesn't exist. +/** + * Copies the data from another point + * + * @param point {PIXI.Point|{PIXI.ObservablePoint} point to copy from + */ +ObservablePoint.prototype.copy = function (point) +{ + if (this._x !== point.x || this._y !== point.y) + { + this._x = point.x; + this._y = point.y; + this.cb.call(this.scope); + } }; diff --git a/src/core/display/ObservablePoint.js b/src/core/display/ObservablePoint.js index 4d65964..836fcdd 100644 --- a/src/core/display/ObservablePoint.js +++ b/src/core/display/ObservablePoint.js @@ -1,11 +1,12 @@ /** + * The Point object represents a location in a two-dimensional coordinate system, where x represents + * the horizontal axis and y represents the vertical axis. * An observable point is a point that triggers a callback when the point's position is changed. * * @class * @memberof PIXI - * - * @param cb {function} The function to be called when the point changes - * @param scope {*} The scope to be applied to the cb + * @param cb {Function} callback when changed + * @param scope {Object} owner of callback * @param [x=0] {number} position of the point on the x axis * @param [y=0] {number} position of the point on the y axis */ @@ -37,8 +38,10 @@ }, set: function (value) { - this._x = value; - this.cb.call(this.scope); + if (this._x !== value) { + this._x = value; + this.cb.call(this.scope); + } } }, /** @@ -54,8 +57,10 @@ }, set: function (value) { - this._y = value; - this.cb.call(this.scope); + if (this._y !== value) { + this._y = value; + this.cb.call(this.scope); + } } } }); @@ -69,8 +74,27 @@ */ ObservablePoint.prototype.set = function (x, y) { - this._x = x || 0; - this._y = y || ( (y !== 0) ? this._x : 0 ); + var _x = x || 0; + var _y = y || ( (y !== 0) ? _x : 0 ); + if (this._x !== _x || this._y !== _y) + { + this._x = _x; + this._y = _y; + this.cb.call(this.scope); + } +}; - this.transform._versionLocal++; // TODO: Pretty sure this doesn't exist. +/** + * Copies the data from another point + * + * @param point {PIXI.Point|{PIXI.ObservablePoint} point to copy from + */ +ObservablePoint.prototype.copy = function (point) +{ + if (this._x !== point.x || this._y !== point.y) + { + this._x = point.x; + this._y = point.y; + this.cb.call(this.scope); + } }; diff --git a/src/extras/BitmapText.js b/src/extras/BitmapText.js index 69b5b88..6f1cdb9 100644 --- a/src/extras/BitmapText.js +++ b/src/extras/BitmapText.js @@ -1,5 +1,5 @@ var core = require('../core'), - math = require('../core/math'); + ObservablePoint = require('../core/display/ObservablePoint'); /** * A BitmapText object will create a line or multiple lines of text using bitmap font. To @@ -106,22 +106,12 @@ this.maxLineHeight = 0; /** - * The anchor sets the origin point of the text. - * The default is 0,0 this means the text's origin is the top left - * Setting the anchor to 0.5,0.5 means the text's origin is centered - * Setting the anchor to 1,1 would mean the text's origin point will be the bottom right corner - * - * @member {PIXI.Point} - */ - this.anchor = new math.Point(); - - /** - * Private tracker for the anchor. This allows us to check whether there has been a change + * Text anchor. read-only * * @member {PIXI.Point} * @private */ - this._anchor = this.anchor.clone(); + this._anchor = new ObservablePoint(this.makeDirty, this, 0, 0); /** * The dirty state of this object. @@ -179,6 +169,28 @@ }, /** + * The anchor sets the origin point of the text. + * The default is 0,0 this means the text's origin is the top left + * Setting the anchor to 0.5,0.5 means the text's origin is centered + * Setting the anchor to 1,1 would mean the text's origin point will be the bottom right corner + * + * @member {PIXI.Point | number} + */ + anchor: { + get : function() { + return this._anchor; + }, + set: function(value) { + if (typeof value === 'number'){ + this._anchor.set(value); + } + else { + this._anchor.copy(value); + } + } + }, + + /** * The font descriptor of the BitmapText object * * @member {string|object} @@ -405,13 +417,6 @@ */ BitmapText.prototype.validate = function() { - // Detect whether the anchor has been updated - if (!this.anchor.equals(this._anchor)) - { - this.dirty = true; - this._anchor.copy(this.anchor); - } - if (this.dirty) { this.updateText(); @@ -419,4 +424,8 @@ } }; +BitmapText.prototype.makeDirty = function() { + this.dirty = true; +}; + BitmapText.fonts = {};