开发者

actionscript child sprite coordinate

开发者 https://www.devze.com 2022-12-25 18:28 出处:网络
I have 3 square. smallest square s3 is inside s2. s2 is in side s1. each is 10px larger var s开发者_运维技巧1:Sprite = new Sprite();

I have 3 square. smallest square s3 is inside s2. s2 is in side s1. each is 10px larger

var s开发者_运维技巧1:Sprite = new Sprite();
var s2:Sprite = new Sprite();
var s3:Sprite = new Sprite();

s2.addChild(s3);
s1.addChild(s2);

how can I find the coordinate of child in its parent's coordinate system?

Inside s3

trace(x) //10
trace(parent.childXof(s3)) //20 how do I get this?


What you are looking for is the localToGlobal and globalToLocal methods of DisplayObjects

Links to documentation:

http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/DisplayObject.html#globalToLocal%28%29

http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/DisplayObject.html#localToGlobal%28%29

They allow you to transform a point from one coordinate space to the other, which is what you are looking to do.

Hope it helps!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号