Davaaron Posted August 30, 2018 Share Posted August 30, 2018 Hi, I got a sprite who got some anchor points for dynamically attaching other sprites to it. As the complete sprite (with its children) will be moved along a path while rotation and stuff like that, I prefer using a single sprite and attaching the sprites to the parent sprite instead of using groups. However, I do not understand how the position of the children is related to the parent. The goal is, obviously, to put the children to their according anchor points of the parent. The anchor points' positions are relative to the parent, for example {x: 70, y:0}. When I just say var parent = game.add.sprite(...); var anchorPoint1 = getAnchorPoint(1); var child1 = game.add.sprite(...); child1.x = anchorPoint1.x; child1.y = anchorPoint1.y; parent.addChild(child1); I would expect, that the child1 sprite would have the position {x:70, y:0) relative to the parent sprite. But instead, it seems like the position something else. I couldnt figure out what's effecting the position. Somebody knows that? Furthermore, the parent got a scale factor of {x: 0.5, y:0.5} and the child1 sprite too like {x:0.9, y:0.9}. When adding the child1 to the parent, the child1 sprite is much much smaller than it actually should be. Is the child1 scale factor influenced by the parent scale? How can I reset the child1 so that it fit its own scale? Link to comment Share on other sites More sharing options...
Davaaron Posted August 30, 2018 Author Share Posted August 30, 2018 Oops, for the position I got the following solution: I've set the anchor to 0.5 for all and reset the position based on the centerX and centerY. But I still couldn't figure out the problem with the scale. Edit: Alright. Everything is cleared up. This example helped me: Limiting scale Link to comment Share on other sites More sharing options...
Recommended Posts