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

Phaser.Physics.P2.addPolygon now takes a flat array, but not a nested array any more #1060

Closed
wayfu opened this issue Jul 22, 2014 · 3 comments

Comments

@wayfu
Copy link

commented Jul 22, 2014

as opposed to #883 :)

the fix is relatively straightforward though:

        //  Did they pass in a single array of points?
        if (points.length === 1 && Array.isArray(points[0]))
        {
            path = points[0].slice(0);
        }
        else if (Array.isArray(points[0]))
        {
            path = points;
        }
        else if (typeof points[0] === 'number')
        {
            //  We've a list of numbers
            for (var i = 0, len = points.length; i < len; i += 2)
            {
                path.push([points[i], points[i + 1]]);
            }
        }
@petarov

This comment has been minimized.

Copy link
Contributor

commented Jul 23, 2014

yep, these work:

var res = contra.body.addPolygon({}, [0, 0, 0, 50, 50, 50, 50, 0]);
var res = contra.body.addPolygon({}, 0, 0, 0, 50, 50, 50, 50, 0);

and

var res = contra.body.addPolygon({}, [[0, 0], [0, 50], [50, 50], [50, 0]]);

does no longer work. I knew I missed a test case. sigh

@valueerrorx

This comment has been minimized.

Copy link

commented Jul 30, 2014

is this the reason why convertCollisionObjects on an object layer from tiled does not work anymore and throws an error:
TypeError: a is undefined phaser.js:65567

???

@photonstorm

This comment has been minimized.

Copy link
Owner

commented Jul 31, 2014

@valueerrorx probably - have a look at your json file, are the objects defined by nested arrays? If so, that's the cause, although the fix I just uploaded resolves it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.