Jump to content

How to add anchor for setTransform on PIXI.Container


jSwtch
 Share

Recommended Posts

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(00, myRatio, myRatio);
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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