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

Scaling problem with bodies #428

Closed
bkjohnson opened this issue Jun 11, 2017 · 2 comments
Closed

Scaling problem with bodies #428

bkjohnson opened this issue Jun 11, 2017 · 2 comments
Labels

Comments

@bkjohnson
Copy link

bkjohnson commented Jun 11, 2017

I've been trying to get a zoom effect on multiple bodies so that means that I need them all to scale to the same point, rather than to their own midpoints. I looked at the code and i looks like the optional point parameter for Body.scale() isn't being used at all despite what the documentation says.

The reason I'm not just changing the width/height bounds is that I'm not trying to scale/zoom on everything, I'm going for a layered effect. I did a bit of testing and I believe something adding the center variable like this would fix the issue:

    Body.scale = function(body, scaleX, scaleY, point) {
        let center = (point == null) ? body.position : point
        for (var i = 0; i < body.parts.length; i++) {
            var part = body.parts[i];

            // scale vertices
            Vertices.scale(part.vertices, scaleX, scaleY, center);
    ...
    }

Any thoughts about this? Should I submit a PR?

Edit: Moved the declaration out of the loop

@liabru liabru added the bug label Jun 12, 2017
@liabru
Copy link
Owner

liabru commented Jun 12, 2017

I looked at the code and i looks like the optional point parameter for Body.scale() isn't being used at all despite what the documentation says.

Hey, looks like this is a bug. Thanks for raising.

I've been trying to get a zoom effect on multiple bodies so that means that I need them all to scale to the same point, rather than to their own midpoints.

Did you try using Composite.scale? I think that one actually does work with a point and for multiple bodies too, see the demo.

@bkjohnson
Copy link
Author

I started using World but then switched to a Composite since it made more sense, and that has helped some but there is still something not quite working right. I try to scale my PIXI container and my Matter.js Composite by the same factor yet it is looking like the Matter one isn't scaling enough to stay in sync with the Pixi one. I made a rough example to show what I'm talking about: move the bunny with WASD and press Tab once to scale the Composite that the green square is in. After scaling you are able to clip through the square and the square responds to collisions from a body that isn't properly lined up with the sprite that you see.

@liabru liabru closed this as completed in 894c1ef Nov 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants