When I'm using Bodies.fromVertices, I receive this error:
Uncaught TypeError: decomp.Polygon is not a constructor at Object.n.fromVertices (matter.min.js:49)
I've already included decomp.min.js at index.html:
<script src="js/matterjs/decomp.min.js" type="text/javascript"></script>
<script src="js/matterjs/matter.min.js"></script>
I'm using this code:
Bodies.fromVertices(0, 0, [], {
isStatic: true
});
What is wrong?
Any update of this?
I couldn't find decomp.Polygon referenced in the code, what matter.js version are you using?
I'm using the latest version of matter.js
https://github.com/liabru/matter-js/tree/master/build
This error appear when I'm trying to create an concave polygon (but error does still appear on empty array) from fromVertices
I just realised you said you're doing this:
Bodies.fromVertices(0, 0, [], {
isStatic: true
});
Since you're not passing any vertices this will fail.
Is there a reason you need a body with no vertices?
Yes because I want to create later Vertices, because vertices is currently not known. But Body should be already created. However, even if I initialize directly in fromVertices, then I'm still getting this error.
I can upload an example project where this errors appear
MatterJS-Example-decompPolygon-Issue.zip
There we go!
I get this error:

Bodies.fromVertices is at line 69 in main.js
matter.js and decomp.js is the latest version, directly from github
You should just directly use Body.create for this instead (though it's really not designed to handle empty vertices).
That said, try this:
var body = Matter.Body.create({ vertices: [{}] });
// later
Body.setVertices(body, [...]);
can ".setVertices" use concave polygons? I don't think so
It can't unfortunately. Is there not a way you can just create the body at the time you need it? It's what I'd recommend.
Fine, I could write that I can create body at the same time when I need it. But however, this doesn't fix issue due decomp.Polygon error from Bodies.fromVertices where I want to create concave polygons. Look up at example where I uploaded here.
@Chinafreak the version of Matter.js in the zip file you uploaded above is _really_ old, it's version 0.10.0. You need 0.13.0. You said you had the latest version from the build folder here, but that is not what is in your zip file, so I think something got mixed up somewhere.
Put the proper version in and you won't get this error.
Ah, I got it from releases where the build is old I guess. https://github.com/liabru/matter-js/releases
Sorry for that! Thanks for the hint @photonstorm! Now everything works fine
might want to update at Release
Yeah I hit the same error, would be good to update the Release
See my latest comment on #559 for an update on this, but essentially try using 0.15.0 as that should solve problems with the require. Let me know in that thread if there are other problems, so closing this one.
Most helpful comment
@Chinafreak the version of Matter.js in the zip file you uploaded above is _really_ old, it's version 0.10.0. You need 0.13.0. You said you had the latest version from the build folder here, but that is not what is in your zip file, so I think something got mixed up somewhere.
Put the proper version in and you won't get this error.