AddTo From one parent to other with same scale

When we move child from one parent to other with addTo() the chilld dont save the scale of the parent.

here in the blue rectangle:
ZIM Editor - JavaScript Canvas Online Code Editor and Viewer (

let con = new Container()
let rectGreen =  new Rectangle(100,100,blue).centerReg(con);,-200);;


there is any fast sollotion?
for now i do that:

let rectSize = rect.boundsToGlobal();
rect.width = rectSize.width;

Yes that logic makes sense to me. Is there a reason why the child should keep the scale if you move it to another parent?

Take for this example below, I wouldn't want the rec to keep the original parent's scale.

const con1 = new Container();
const rec = new Rectangle().addTo(con);,0);

const con2 = new Container();,0);

1 Like

Mebe to set some function or in the addTo set "saveSize" or something like that.
In my game i use addTo to enter items to parents and move it like the parent.
And when i take it out or to other parent the scale change (in the view)

You are moving an object from under one scale into a different scale, so you have to change the object's scale in a relative way. For example

  • parent #1 is 200% scale and has child
  • parent #2 is 50% scale
  • both parents share the same scale themselves (at 100% they are the same stage scale)

...given that, moving from parent #1 to parent #2 means the child will need to be scaled by 400% to be the same size visually.

// Forces proportional scaling based on scaleX
const childScaleFactor = targetParent.scaleX / currentParent.scaleX;
child.scaleX = child.scaleY = child.scaleX * childScaleFactor;

Of course, you'll also have to consider x and y transitions since different scales mean different positions. Use localToLocal or some localToGlobal and globalToLocal translations.

You right,
but the user see the object on one size and they didnt care if it change parent. :slight_smile: