Jump to content

Why should pivot work like this?


dominate
 Share

Recommended Posts

What I understood from "pivot" was that it was the point of rotation, as it is described.

But the result is: It has unnecessary side-effect. It creates an offset.

 

Could some body explain me if this side-effect was necessary, especially if we have there already "anchor" to make an offset?

 

Think that rotation = 0. Then I am setting pivot. Ooopps!! I have lost the position of the object.

So, every time I modify the pivot, just with intent to change the point of rotation, I have to set the position again accordingly.

 

Why?

Link to comment
Share on other sites

The pivot is the sprite's origin for transformation it is not just for rotation, but translation and scaling as well. Think of it as the centre of the sprite, even though it doesn't have to be in the middle of the sprite's actual bounds. (Phaser uses matrices for transformation, the pivot is literally the sprite's origin)

The anchor lets you offset the texture/image used to draw a sprite. I believe it to be the less useful of the two coords being discussed (though it still has it's uses...)

If you visualise a Phaser Sprite object imagine it as having two overlapping rectangles that can be offset from each other (by the distance between the anchor and the pivot, perhaps also imagine a little + at the pivot point centre for convenience). One rectangle is the sprite's texture frame (ie. the image displayed for that animation frame for the sprite), while the other is it's actual bounds (eg. used for collision maybe).

...At least that I think how it is. If you don't need both and need rotation and/or scaling (and don't need a separate offset for the textures, beyond the point about which transforms take place then) just use pivot.

Link to comment
Share on other sites

Could some body explain me if this side-effect was necessary, especially if we have there already "anchor" to make an offset?

 

There have been many prior discussions about this both in this forum and on Pixi's Github repo over the years, like this:

 

https://github.com/pixijs/pixi.js/issues/190

 

Some people, like me, actually thought this was a bug in Pixi, because of the weird way `pivot` works and the fact that the side-effect you mentioned wasn't in the documentation.

However, it turned out this was actually the way `pivot` was supposed to work.

 

But I personally think it's a bad behaviour.

I would love it if Pixi had some way to set the rotation point of a sprite without shifting its x/y position.

This would be a huge win in so many ways.

(I've had to write my own custom `pivotX` and `pivotY` sprite methods to implement this feature in my own projects.)

 

Chad Engler proposed to fix this, but sadly it was never implemented.

 

https://github.com/pixijs/pixi.js/issues/997

 

If there was only one single thing I could ever change about Pixi, it would be to implement Chad's proposal.

Link to comment
Share on other sites

On 1/11/2016 at 2:22 AM, d13 said:

 

There have been many prior discussions about this both in this forum and on Pixi's Github repo over the years, like this:

 

https://github.com/pixijs/pixi.js/issues/190

 

Some people, like me, actually thought this was a bug in Pixi, because of the weird way `pivot` works and the fact that the side-effect you mentioned wasn't in the documentation.

However, it turned out this was actually the way `pivot` was supposed to work.

 

But I personally think it's a bad behaviour.

I would love it if Pixi had some way to set the rotation point of a sprite without shifting its x/y position.

This would be a huge win in so many ways.

(I've had to write my own custom `pivotX` and `pivotY` sprite methods to implement this feature in my own projects.)

 

Chad Engler proposed to fix this, but sadly it was never implemented.

 

https://github.com/pixijs/pixi.js/issues/997

 

If there was only one single thing I could ever change about Pixi, it would be to implement Chad's proposal.

Fortunately there is someone who understood what I mean.

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