diff --git a/src/extras/getGlobalPosition.js b/src/extras/getGlobalPosition.js new file mode 100644 index 0000000..258da09 --- /dev/null +++ b/src/extras/getGlobalPosition.js @@ -0,0 +1,31 @@ +var DisplayObject = require('../core/display/DisplayObject'), + Point = require('../core/math/Point'); + + +/** +* Returns the global position of the displayObject +* +* @param point {Point} the point to write the global value to. If null a new point will be returned +* @return {Point} +*/ +DisplayObject.prototype.getGlobalPosition = function (point) +{ + point = point || new Point(); + + if(this.parent) + { + this.displayObjectUpdateTransform(); + + point.x = this.worldTransform.tx; + point.y = this.worldTransform.ty; + } + else + { + point.x = this.position.x; + point.y = this.position.y; + } + + return point; +}; + +module.exports = {}; diff --git a/src/extras/getGlobalPosition.js b/src/extras/getGlobalPosition.js new file mode 100644 index 0000000..258da09 --- /dev/null +++ b/src/extras/getGlobalPosition.js @@ -0,0 +1,31 @@ +var DisplayObject = require('../core/display/DisplayObject'), + Point = require('../core/math/Point'); + + +/** +* Returns the global position of the displayObject +* +* @param point {Point} the point to write the global value to. If null a new point will be returned +* @return {Point} +*/ +DisplayObject.prototype.getGlobalPosition = function (point) +{ + point = point || new Point(); + + if(this.parent) + { + this.displayObjectUpdateTransform(); + + point.x = this.worldTransform.tx; + point.y = this.worldTransform.ty; + } + else + { + point.x = this.position.x; + point.y = this.position.y; + } + + return point; +}; + +module.exports = {}; diff --git a/src/extras/index.js b/src/extras/index.js index e54848e..fc4ac98 100644 --- a/src/extras/index.js +++ b/src/extras/index.js @@ -14,5 +14,6 @@ TilingSprite: require('./TilingSprite'), BitmapText: require('./BitmapText'), cacheAsBitmap: require('./cacheAsBitmap'), - getChildByName: require('./getChildByName') + getChildByName: require('./getChildByName'), + getGlobalPosition: require('./getGlobalPosition') };