Issue 85 in sekati: shortcut for reparenting a DisplayObject

2 views
Skip to first unread message

sek...@googlecode.com

unread,
Oct 6, 2010, 5:13:40 PM10/6/10
to sekat...@googlegroups.com
Status: New
Owner: ----
Labels: Type-Enhancement Priority-Low Milestone-0.x.x.x

New issue 85 by iworkinprogress: shortcut for reparenting a DisplayObject
http://code.google.com/p/sekati/issues/detail?id=85

Purpose of the enhancement request:
- Easily reparent a Display Object while mainting visual scale, position,
and rotation.
- Note: * I didn't write this. Found it here:
http://www.actionscript.org/forums/showthread.php3?t=154569
- But it works like magic when you want to move a Sprite deeply nested onto
stage and from within scaled and rotated parents.

Would this request break the existing API, add new functionality or both?
Add new functionality

Please use labels, example code and attachments to provide additional info:

Should go into CoreSprite

public function switchParentTo (newParent:DisplayObjectContainer):void {
var oldParent:DisplayObjectContainer = parent;
var newpoint:Point = new Point();
newpoint.x=0;
newpoint.y=0;
newpoint =
newParent.globalToLocal(this.localToGlobal(newpoint));
while (oldParent!=root) {
rotation+=oldParent.rotation;
scaleX*=oldParent.scaleX;
scaleY*=oldParent.scaleY;
oldParent = DisplayObjectContainer(oldParent.parent);
}
newParent.addChild(this);
while (newParent!=root) {
rotation-=newParent.rotation;
scaleX/=newParent.scaleX;
scaleY/=newParent.scaleY;
newParent = DisplayObjectContainer(newParent.parent);
}
x=newpoint.x;
y=newpoint.y;
}

sek...@googlecode.com

unread,
Dec 1, 2010, 12:27:59 PM12/1/10
to sekat...@googlegroups.com
Updates:
Status: Pending

Comment #1 on issue 85 by sekati: shortcut for reparenting a DisplayObject
http://code.google.com/p/sekati/issues/detail?id=85

Please test this as a slightly less intrusive solution (to be released in
DisplayUtil):

/**
* Reparent a display object while maintianing its visual continuity by
syncing it's scale & rotation properties.
*/
public static function reParentDisplayObjects(object : DisplayObject,
newParent : DisplayObjectContainer) : void {
var oldParent : DisplayObjectContainer = object.parent;


var newpoint : Point = new Point( );
newpoint.x = 0;
newpoint.y = 0;

newpoint = newParent.globalToLocal( object.localToGlobal( newpoint ) );
while (oldParent != Canvas.stage.root) {
object.rotation += oldParent.rotation;
object.scaleX *= oldParent.scaleX;
object.scaleY *= oldParent.scaleY;
oldParent = DisplayObjectContainer( oldParent.parent );
}
newParent.addChild( object );
while (newParent != Canvas.stage.root) {
object.rotation -= newParent.rotation;
object.scaleX /= newParent.scaleX;
object.scaleY /= newParent.scaleY;
newParent = DisplayObjectContainer( newParent.parent );
}
object.x = newpoint.x;
object.y = newpoint.y;
}

sek...@googlecode.com

unread,
Dec 1, 2010, 2:01:07 PM12/1/10
to sekat...@googlegroups.com
Updates:
Status: Fixed

Comment #2 on issue 85 by sekati: shortcut for reparenting a DisplayObject
http://code.google.com/p/sekati/issues/detail?id=85

Added for release in 3.0.6.1

Reply all
Reply to author
Forward
0 new messages