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 (zimjs.com)
let con = new Container()
let rectGreen = new Rectangle(100,100,blue).centerReg(con);
con.center().mov(0,-200);
con.sca(0.5);
con.on("mousedown",()=>{
rectGreen.addTo();
S.update();
})
there is any fast sollotion?
for now i do that:
let rectSize = rect.boundsToGlobal();
rect.addTo();
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);
con1.sca(1.5).center().mov(-100,0);
const con2 = new Container();
con2.sca(2).center().mov(100,0);
rec.addTo(con2);
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;
targetParent.addChild(child);
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.
Will put it on the list as something to consider. We do automatically adjust coordinate issues with addTo() unless still parameter is set to false - then it goes to the "original" way where you would have to translate x and y. But we did not do that for scale and rotation. Anyway... not sure if we will adjust as this is less of an issue. But it is on the list to consider. Thanks.