Jump to content

Using non-convex polygons sprites (P2 physics)


Recommended Posts

I started using Phaser recently, and I came across a problem that kind of annoyed me since I didn't find any really satisfying answers yet (on this forum or anywhere on the internet)

I'm trying to create non-convex polygon-shaped sprites, I know I have to use P2 physics to accomplish that, and precisely the loadPolygon function. The thing is, everyone seems to be working with PhysicsEditor to generate JSON files to feed this function, and I'm looking for a free alternative.

I eventually found 2 alternatives, but :

- https://loonride.com/tools/physics : doesn't seems to work (clicking on "downloads" or "URLs & code" does absolutely nothing)

- http://subefotos.esy.es/PhysicsEditor/ : for some reason, everytime I click "New image", my PC freezes to death... (I tried on a different PC and it works, but even then you have to create manually all the "polygon groups", and I'm looking for something that would generate these for me)

I put together a little editor that lets you define points on a sprite and triangulate the polygon to create the desired JSON file (that contains the list of these triangles), but I'm wondering if there is a simpler way to answer this problematic ? I also tried to use addPolygon, but there was this weird offset because Phaser wants to adjust the center of mass, I didn't find how to avoid that (just commenting the call to the function which adjust the center of mass, as I've read on this forum, didn't do the trick, the offset was different but still there)


Thanks !

Link to comment
Share on other sites

Thank you!

I had already tested this one, but not successfully, and the fact that its last update is from 2012 had me thinking it wasn't the response to my problem...

Well, I insisted and this actually seems to be perfect! I just have to write something to converts the output to the phaser format, but it seems easy enough


I guess I can stop working on my editor, even though it was fun to learn a few things about polygon triangulation/decomposition ^_^

Link to comment
Share on other sites


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...