Jump to content

Sprite add child


Recommended Posts



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;


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


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...