jSwtch Posted September 18, 2019 Share Posted September 18, 2019 How do I change transform origin of a container? I am reading the docs and there is no anchor.set like sprites. This code apples the transform I want to all container children but it appears they are scaled from bottom left corner - I want to change this origin. myContainer.setTransform(0, 0, myRatio, myRatio); Quote Link to comment Share on other sites More sharing options...
ivan.popelyshev Posted September 18, 2019 Share Posted September 18, 2019 OK, I answer that question for 100th time Transform is calculated from position.scale.rotation.pivot. If you change "position" and "pivot" at the same time, you can get any origin. Here's how to use pivot, basically: https://pixijs.io/examples/#/demos-basic/container.js Consider you have position pos and you want to rotate or scale around "origin" in local coords. that's how you do it: container.position.set(pos.x + origin.x, pos.y + origin.y); container.pivot.set(origin.x, origin.y); Why is that? Spend more time with pixi and you'll get it. Position is where you pin container in global coordinate system, pivot is in local, its like you pin two sheets of paper with a needle. You want to make container in center of screen? Set position to center of screen and pivot to your local center whatever you want to be , for example player character coordinates. As to why is there is no anchor - container width and height are calculated props, they are based on children, and if there would be an anchor - it will have very not obvious feedback. jSwtch 1 Quote Link to comment Share on other sites More sharing options...
jSwtch Posted September 19, 2019 Author Share Posted September 19, 2019 thanks Ivan! Worked like a charm myContainer.setTransform( widthPoint, heightPoint, scaleRatio, scaleRatio, 0, 0, 0, widthPoint, heightPoint ); 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.