Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pivot affects object position #190

Closed
ppoliani opened this issue Jul 6, 2013 · 24 comments
Closed

pivot affects object position #190

ppoliani opened this issue Jul 6, 2013 · 24 comments
Assignees
Labels
🕷 Bug Verified that it’s actually a legit bug that exists in the current release.
Milestone

Comments

@ppoliani
Copy link

ppoliani commented Jul 6, 2013

I have a question with regards to the pivot property of a DisplayObject. In particular, i want to rotate a DisplayObjectContainer around its center; so i set the pivot to its center point. However, i've noticed that this affects the position of the element.

For example, if i set the position to 0,0 (which is the default one) pixijs will try to position the object according to its center point and not the top left corner. So the children of the the DisplayObjectContainer (which in my case is an instance of the Graphics class) run out of the left and top edges of the viewport.

Is there any way to set the rotation point but still position the object in respect to its top left corner.

@mccraveiro
Copy link

I managed to do this by setting the pivot and position of the graphics to its center, and then I drew the graphics around this point.

@sjlynch
Copy link

sjlynch commented Aug 2, 2013

I answered your question on stackoverflow with a code example here: http://stackoverflow.com/questions/17505169/pixi-js-pivot-affects-object-position/18007977#18007977

@englercj
Copy link
Member

@GoodBoyDigital Is pivot effecting position, and if so is that a quick fix?

@ghost ghost assigned GoodBoyDigital Aug 19, 2013
@drkibitz
Copy link
Contributor

I've actually been confused about pivot and anchor, can these be merged?

@englercj
Copy link
Member

Well, pivot and anchor are different (conceptually). Pivot affects the point of rotation, while anchor is the origin (point of the position). I'm not sure if pivot is being used properly though.

@drkibitz
Copy link
Contributor

It sounds like this can be used as the same point. I've actually never seen these separated before in rendering (css transform-origin, flash's registration) was there a use case this accounted for? If so, can everything default to one thing, and then use another if set?

Maybe default to anchor everywhere including rotation, unless pivot is a point, use that for rotation?

UPDATE: Or vice versa of the above, though I'm leaning toward anchor = default, and pivot = rotation, better naming IMO.

@englercj
Copy link
Member

anchor and pivot are pretty common in rendering engines. There are many use cases where you want to rotate about the center but have the position determined by the top-left. It is something we not only should support, but will.

@GoodBoyDigital
Copy link
Member

Howdy, looking into this issue one now. For a little clarification the anchor is a sprite specific thing. Its used to align the texture. I found the feature incredibly useful when I was making stuff with cocos2d back in the day so really wanted to add it to pixi. The pivot belongs to all display objects and essentially is the point of rotation.

@englercj
Copy link
Member

Closing this as solved, pivot/anchor are working as intended.

@mparker11
Copy link

Sorry for bringing this up but I've been searching/reading through this repo and I'm still not clear on how to rotate a DisplayObjectContainer from the center. Using pivot is not allowing my container to flip from the center without moving elsewhere. Any ideas? I saw #93 and thought that was the answer, but maybe I'm not understanding it correctly. Any help would be appreciated. Thanks!

Edit: I thought it would be helpful to mention that my object is moving across the screen and will be flipping while moving. I'm also using scale to do the "flipping".

@englercj
Copy link
Member

@mparker11 Rotating around a point and flipping (via scale) is different. pivot will affect the value in rotation, I'm not sure if you can properly affect how a container flips with scale...

Thoughts @GoodBoyDigital?

@mparker11
Copy link

@englercj Thanks for the response. I read an article about using matrix multiplication to achieve it, which I see that @GoodBoyDigital used in his PIXI.DisplayObject.prototype.updateTransform function, but for the life of me I can't really understand how to change it to make it scale from the center, if I even need to change it.

@tleunen
Copy link

tleunen commented Feb 14, 2014

Hmmm... Definitely don't understand how to use the pivot.

I set the position of a sprite at a given position. Then I'd like to make it rotate at its center, so I set the pivot at the center of my sprite (sprite.width/2, sprite.height/2). This result in moving my sprite and having the rotation at 0,0.

Uh? Did I miss something?

@mparker11
Copy link

@tleunen I believe you need to use anchor since you are using Sprites.

@ivan-kleshnin
Copy link

Will this behavior be fixed in v4?

I decided to try Pixi out and immediately hit this "bug".
After a few hours googling I still don't understand how this is supposed to work.
Most people on forums just say "pivot behavior is broken". Not very helpful.

@GoodBoyDigital
Copy link
Member

Neither is your comment I'm afraid. This is the way pixi deals with pivot.
If this 'bug' is too much to bare please provide a pr or jog on..

On Thursday, 10 March 2016, Ivan Kleshnin notifications@github.com wrote:

Will this behavior be fixed in v4?

I decided to try Pixi out and immediately hit this "bug".
After a few hours googling I still don't understand how this supposed to
work.
Most people on forums just say "pivot behavior is broken". Not very
helpful.


Reply to this email directly or view it on GitHub
#190 (comment).

Mat Groves

Technical Partner

Telephone: 07708 114496 :: www.goodboydigital.com
First Floor, Unit 9B, Queens Yard, White Post Lane, London, E9 5EN
goodboy©. All Rights Reserved.

@ivan-kleshnin
Copy link

Neither is your comment I'm afraid

Please do not take "Not very helpful" personally.
It was meant to describe my emotional state, not to offend.

If this 'bug' is too much to bare please provide a pr or jog on..

I don't know whether it's a bug or not because I'm a noob in this industry.
That's why I put a "bug" word above in quotes. Some people consider it is. Some – its is not.
I just shared my experience and asked about change in v4. I really wanted to learn Pixi but this one took me down.

The main problem: after reading >10 related issues (here and on the internet) I still don't get how to workaround this behavior and force a container to rotate around it's center in defined point of space.
And I'm not that especially stupid.

@GoodBoyDigital
Copy link
Member

Hi there!

No worries man, sorry if I was a bit short, you caught me at the end of a long day!

Pivot is meant to behave as a non normalised anchor point.

The easiest way to fix it is to add the object into a container and rotate the container, whilst moving the object around internally.

Hope that helps!

@ivan-kleshnin
Copy link

No problem. Thanx. I'll try to use your advice.

@matejbart
Copy link

In my opinion, the easiest way to rotate a graphic (or a container) around its center point is to save the center point coordinates, where a graphic was drawn. Then, set the position and the pivot of the graphic to the center point.
Here is an example:

If you for example create a graphic object, you can start to draw primitives on it.
var test = new PIXI.Graphics(); test.drawRoundedRect(100, 100, 200, 200,12);
The primitive is always drawn relative to the position of the Graphics object (which is 0 as default).
Therefore, we need to set the new position of the graphic object to 200, because it's the current center point of our primitive.
test.position.x = 200; test.position.y = 200;
Now we can see, that the primitive just has been shifted, therefore we need to set the pivot to the same coordinate and it will stay at the same position, where we had drawn it.
test.pivot.x = 200; test.pivot.y = 200;

The pivot property isn't buggy, it's just a little bit confusing to understand how it works and why it "affects object position". The object is always rotating around the own position and the pivot helps us to set a new point from where it rotates.

@jdnichollsc
Copy link

Hello guys! Can I use the pivot with angles? I'm trying to modify the angle of one sprite (using the pivot to modify the rotation position) to follow the mouse, but I can't, can you help me, please?

Check my codepen example => http://codepen.io/jdnichollsc/pen/KgdRvV?editors=0010
And the error => http://screencast.com/t/hSSaaTO4j0

Thanks in advance, Nicholls

@jdnichollsc
Copy link

Done! Only using pivot.y or pivot.x hahaha! Thanks for all Pixi team! 👍

@gai-sama
Copy link

In my opinion, the easiest way to rotate a graphic (or a container) around its center point is to save the center point coordinates, where a graphic was drawn. Then, set the position and the pivot of the graphic to the center point.
Here is an example:

If you for example create a graphic object, you can start to draw primitives on it.
var test = new PIXI.Graphics(); test.drawRoundedRect(100, 100, 200, 200,12);
The primitive is always drawn relative to the position of the Graphics object (which is 0 as default).
Therefore, we need to set the new position of the graphic object to 200, because it's the current center point of our primitive.
test.position.x = 200; test.position.y = 200;
Now we can see, that the primitive just has been shifted, therefore we need to set the pivot to the same coordinate and it will stay at the same position, where we had drawn it.
test.pivot.x = 200; test.pivot.y = 200;

The pivot property isn't buggy, it's just a little bit confusing to understand how it works and why it "affects object position". The object is always rotating around the own position and the pivot helps us to set a new point from where it rotates.

Hey dude,I think that was a hack,cause it has a side effect: the position has been changed.

@lock
Copy link

lock bot commented Dec 23, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked and limited conversation to collaborators Dec 23, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🕷 Bug Verified that it’s actually a legit bug that exists in the current release.
Projects
None yet
Development

No branches or pull requests