Jump to content

[PIXI] Anchor vs Pivot


d13
 Share

Recommended Posts

Hey everyone... I'm trying to understand the difference between Pixi's  `anchor` and `pivot`

This is what I've been able to deduce so far...

 

Anchor shifts the origin point of the sprite's image texture, using a 0 to 1 normalized value.

Pivot shifts the origin of the sprite's x and y point, using pixel values.

 

Is this correct - or brain-dead?  :blink:

Link to comment
Share on other sites

  • 1 year later...
5 hours ago, xerver said:

Kind of.

But I am still confused with the use of pivot in different coordination system. 

For example, I have a map which is a TilingSprite with origin at (0, 0) and it's larger than the canvas size. I want my player sprite in the center of the canvas and it can move around the map. So I use a camera to do that. Suppose my camera is at (camera.x, camera.y) of the map, now the coordination system still has origin at (0, 0).

Now if I set my map position:

map.position.set(render.view.width / 2, render.view.height / 2);

and change its pivot:

map.pivot.set(render.view.width / 2, render.view.height / 2);

It will shift the map origin to the center of the canvas and now the new (0, 0) is actually (render.view.width / 2, render.view.height / 2)? Why can't I just set pivot point as  (render.view.width / 2, render.view.height / 2) without shifting the position? If I don't set the position to  (render.view.width / 2, render.view.height / 2) the map stays at the same place and a pivot set doesn't have any effect. If I scale the map it will still scale to the original (0, 0).

More confusing is that when I move my player my camera moves. But setting the map's pivot to the center of canvas still works as before. How does pivot translate my coordinates when my player's actual (x, y) changes?

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...