Jump to content

How pivot and position work for root container?


Recommended Posts

The stage property on the app we create is the root container of everything that we want to render with PIXI. From what I see in the console, the root container doesn't have its own parent. The default pivot and position for it are both (0, 0), which is the top-left corner of the container.

By default, the children are added at (0, 0), which is now the top-left corner of the root container. I want them to be added at the geometric center of the container so naturally I did stage.pivot.set(renderer.width / 2, renderer.height / 2). However, this doesn't work. Instead, stage.pivot.set(-renderer.width / 2, -renderer.height / 2) gives me the expected result. Could someone explain to me the logic behind this?

Also, from what I understand, position is relative to the parent coordinate. Since stage doesn't have a parent, what does stage.position actually represent?

Link to comment
Share on other sites

position in world coords is pinned to pivot in local.

for example, i want to show a map centered on character.

stage.position.set(renderer.screen.width/2, renderer.screen.height/2); //not view!!! start using DPR>1 and you'll understand why ;)
stage.pivot.set(character.x, character.y);

stage.scale.set(2); //zoom it!


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.

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.


  • Recently Browsing   0 members

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