Advertisement
Guest User

Untitled

a guest
Mar 26th, 2016
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Get the position of a DisplayObject relative to another DisplayObject or the stage
  3.  *
  4.  * @param [parent] {DisplayObject} The DisplayObject to calculate the relative position to
  5.  * @param [position] {Point} The position of the precedent DisplayObject in the recursive chain
  6.  * @return {Point} A point object representing the position of this object relative a parent or the stage
  7.  */
  8. PIXI.DisplayObject.prototype.getRelativePosition = function(parent,position){
  9.     var position = position || new PIXI.Point();
  10.     var parent = parent || null;
  11.  
  12.     position.x += this.x;
  13.     position.y += this.y;
  14.  
  15.     if(this.parent !== null && this.parent !== parent && this !== parent)
  16.     {
  17.         return this.parent.getRelativePosition(parent,position);
  18.     }
  19.  
  20.     return position;
  21. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement