Created
June 15, 2015 18:31
-
-
Save gonchar/492cdb3bd0b574c0c84d to your computer and use it in GitHub Desktop.
true localToLocal for Starling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private static var transform:Matrix = new Matrix(); | |
private static var transformInverse:Matrix = new Matrix(); | |
private static var path:Vector.<DisplayObject> = new Vector.<DisplayObject>(); | |
public static function localToLocal(source:DisplayObject, target:DisplayObjectContainer = null, objChildOfTarget:Boolean = true):void | |
{ | |
if (target == null || source == null) return; | |
transform.identity(); | |
transform.copyFrom(source.transformationMatrix); | |
var parent:DisplayObject = source as DisplayObject; | |
while (parent && parent.parent != null) | |
{ | |
parent = parent.parent; | |
if (parent == target) | |
{ | |
source.transformationMatrix = transform; | |
target.addChild(source); | |
return; | |
} | |
transform.concat(parent.transformationMatrix); | |
} | |
if (target == null) return; | |
var pathItem:DisplayObject = target; | |
path.length = 0; | |
while (pathItem.parent != null) | |
{ | |
path.push(pathItem); | |
pathItem = pathItem.parent; | |
} | |
var i:int; | |
var length:int = path.length; | |
for (i = length - 1; i >= 0; i--) | |
{ | |
pathItem = path[i]; | |
transformInverse.copyFrom(pathItem.transformationMatrix); | |
transformInverse.invert(); | |
transform.concat(transformInverse); | |
} | |
source.transformationMatrix = transform; | |
if (objChildOfTarget) target.addChild(source); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment