Rumthorp Posted December 2, 2021 Share Posted December 2, 2021 I'm really struggling with getting one sprite to sit on top of another sprite. Each sprite is in a separate container. I've read I'm supposed to use toLocal and toGlobal methods but I can't find any example of those methods being used in this way. I've tried using these methods as described but the sprite positions never match up. The closest I've come to is this: spriteB.position = spriteB.toLocal(spriteA.toGlobal(root.stage.position)); That makes the y axis match but the x is way off. Any help would be appreciated. I've been at this for a while. Quote Link to comment Share on other sites More sharing options...
Exca Posted December 4, 2021 Share Posted December 4, 2021 You could do something like this: // Get the global position of 0,0 (origo of spriteA) in spriteA:s coordinate. const aGlobal = this.spriteA.toGlobal(new Point(0,0)); // Transform that coordinate into the containers (where spriteB is) coordinate system. const aInBContainer = this.spriteB.parent.toLocal(aGlobal); // Set the sprite B position to that coordinate. this.spriteB.position = aInBContainer; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.