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

P2.Body addPolygon mutates points in point array #301

Closed
Plukers opened this issue Jul 27, 2017 · 4 comments
Closed

P2.Body addPolygon mutates points in point array #301

Plukers opened this issue Jul 27, 2017 · 4 comments
Milestone

Comments

@Plukers
Copy link

Plukers commented Jul 27, 2017

  • A bug in the API:
    • Phaser version(s): 2.8.3
    • What should happen: The coordinates in the point array should not change
    • What happens instead: The values are modified
    • Live example:
const s = game.add.sprite(x, y, 'Sprite');
game.physics.p2.enable(s, false);
s.body.clearShapes();

const points = [[10, 20], [30, 40], [50, 60]];
console.log(points.toString()); // 10,20,30,40,50,60
s.body.addPolygon({}, points);
console.log(points.toString()); // -0.5,-1,-1.5,-2,-2.5,-3

I had no chance to take a closer look, but it looks like the mutation happens here physics/p2/Body.js, line 1180

@samme
Copy link
Collaborator

samme commented Jul 27, 2017

I don't think it's a bug, but it may be undesirable. We can add a note to the docs.

Can you try passing a flat array? [10, 20, 30, 40, 50, 60]

@Plukers
Copy link
Author

Plukers commented Jul 27, 2017

I wrote bug because it was the most fitting option, but you are right, it's not a bug, just unexpected.
So a note in the docs would be great, thank you!

I will try it with the flat array tomorrow at work and post the results.

@samme samme modified the milestone: 2.8.4 Jul 27, 2017
@samme
Copy link
Collaborator

samme commented Jul 28, 2017

Understood, thanks.

@samme samme closed this as completed in 1ed4bca Jul 28, 2017
@Plukers
Copy link
Author

Plukers commented Jul 31, 2017

It works with the flat array, the array is not changed.

@samme samme modified the milestone: 2.8.4 Aug 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants