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

Setting the anchor should not redraw the displayobject content #4841

Closed
DavidGOrtega opened this issue Apr 11, 2018 · 4 comments
Closed

Setting the anchor should not redraw the displayobject content #4841

DavidGOrtega opened this issue Apr 11, 2018 · 4 comments
Labels
🤔 Question User question, similar to Help Wanted or Needs Help. These can be addressed whenever someone has tim 💾 v4.x (Legacy) Legacy version 4 support

Comments

@DavidGOrtega
Copy link

Hi,

despite that pivot and anchor is super confusing, If I imagine the anchor as that round point that I can set in photoshop or old flash editor as the rotation point what happens in pixi is that all the displayobject content is redrawn setting the anchor as the origin point.

var app = new PIXI.Application(800, 600, {backgroundColor : 0x1099bb});
document.body.appendChild(app.view);

var bunny = PIXI.Sprite.fromImage('required/assets/basics/bunny.png');

var container = new PIXI.Sprite();
container.addChild(bunny);
container.x = 0;
container.y = 0;

app.stage.addChild(container);

bunny.anchor.set(0.5);
//bunny_c.pivot.set(15,5);

With this example I expect the bunny to be with the anchor that affetcs its rotation changed but not the bunny be redrawn!

@ivanpopelyshev
Copy link
Collaborator

Each element has a transform, which is position/rotation/pivot
Sprites have anchor, that means "this point of texture should be in (0,0) of local coordinate system".

Rotation pivot is always (0,0) of local coordinate system.

If you want different behaviour, you can change the Transform class and create instances of your patched Transform for the affected elements.

https://github.com/pixijs/pixi.js/blob/dev/src/core/display/TransformStatic.js
https://github.com/pixijs/pixi.js/blob/dev/src/core/sprites/Sprite.js#L174

Also, bunny is redrawn every frame in pixi. The library does not have mechanisms to track all the changes, it just works. Otherwise it could weight 3MB or more :)

@ivanpopelyshev
Copy link
Collaborator

For your case, its better to set pivot to bunny's center. Make sure to do it by constants, use bunny.texture.width only when its loaded.

@themoonrat themoonrat added 🤔 Question User question, similar to Help Wanted or Needs Help. These can be addressed whenever someone has tim 💾 v4.x (Legacy) Legacy version 4 support Domain: API labels Jun 30, 2018
@themoonrat
Copy link
Member

@DavidGOrtega closing this as I feel that your question has been answered. Feel free to re-open if you have any further issues!

@lock
Copy link

lock bot commented Jun 30, 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 Jun 30, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🤔 Question User question, similar to Help Wanted or Needs Help. These can be addressed whenever someone has tim 💾 v4.x (Legacy) Legacy version 4 support
Projects
None yet
Development

No branches or pull requests

3 participants