raptorjesus Posted May 21, 2014 Share Posted May 21, 2014 Can anyone tell me or suggest how the polygons were created in the phaser examples? I wanted to make complex shapes like that for collision/p2 physics but am having some difficulty finding how they're made. http://examples.phaser.io/_site/view_full.html?d=p2%20physics&f=load+polygon+1.js&t=load%20polygon%201 http://examples.phaser.io/_site/view_full.html?d=p2%20physics&f=load+polygon+2.js&t=load%20polygon%202 I apologize if this is a real n00b question but I was actually having trouble finding out. Link to comment Share on other sites More sharing options...
rich Posted May 21, 2014 Share Posted May 21, 2014 https://www.codeandweb.com/physicseditor Link to comment Share on other sites More sharing options...
Mike Posted May 21, 2014 Share Posted May 21, 2014 Hi, the polygons are defined here: http://examples.phaser.io/assets/physics/sprites.json To get the coordinates to corresponding format you can also use:http://www.aurelienribon.com/blog/projects/physics-body-editor/ and check this topic here:http://www.html5gamedevs.com/topic/2198-box2d-physics-editor-with-box2dweb-importer/ Link to comment Share on other sites More sharing options...
raptorjesus Posted May 21, 2014 Author Share Posted May 21, 2014 Thanks so much, these answers are exciting, as I wanted to use PhysicsBodyEditor, my problem was I think my workflow, I created a simple shape and exported as JSON but could not get it to import. When I compared the text of the file to one of the sprites json files it looked a lot different. Are there any workflow example of PhysicsBodyEditor use with Phaser? Link to comment Share on other sites More sharing options...
raptorjesus Posted May 22, 2014 Author Share Posted May 22, 2014 When I try this I get ouptut like this from Physics Body Editor, When I try to load using the example code I'm getting TypeError: data.shape is undefined in the console. When I load this into the canvas using example code from Load Polygon 1 I get the error in console: TypeError: data.shape is undefined Any idea what I'm doing wrong?{"shape2":[{"shape2":"Name","imagePath":"mytek-logo.png","origin":{"x":0,"y":0},"polygons":[[{"x":0.29433271288871765,"y":0.11334551870822906},{"x":0.325411319732666,"y":0.009140759706497192},{"x":0.33820840716362,"y":0.0018281340599060059},{"x":0.4113345444202423,"y":0.0018281340599060059},{"x":0.4149908721446991,"y":0.012797057628631592},{"x":0.33820840716362,"y":0.2669104039669037}],[{"x":0.33820840716362,"y":0.2669104039669037},{"x":0.325411319732666,"y":0.2742230296134949},{"x":0.2522851824760437,"y":0.2742230296134949},{"x":0.23948810994625092,"y":0.2577696442604065},{"x":0.21206581592559814,"y":0.162705659866333},{"x":0.28702011704444885,"y":0.11334551870822906},{"x":0.29433271288871765,"y":0.11334551870822906}],[{"x":0.21206581592559814,"y":0.162705659866333},{"x":0.13162705302238464,"y":0.10968920588493347},{"x":0.1608775109052658,"y":0.009140759706497192},{"x":0.1736745834350586,"y":0.0018281340599060059},{"x":0.2468007355928421,"y":0.0018281340599060059},{"x":0.2632541060447693,"y":0.029250457882881165},{"x":0.28702011704444885,"y":0.11334551870822906}],[{"x":0.20109689235687256,"y":0.177330881357193},{"x":0.1736745834350586,"y":0.2669104039669037},{"x":0.1590493619441986,"y":0.2742230296134949},{"x":0.12431444227695465,"y":0.11517366766929626},{"x":0.13162705302238464,"y":0.10968920588493347}],[{"x":0.13162705302238464,"y":0.10968920588493347},{"x":0.21206581592559814,"y":0.162705659866333},{"x":0.20109689235687256,"y":0.177330881357193}],[{"x":0.1590493619441986,"y":0.2742230296134949},{"x":0.0822669118642807,"y":0.2742230296134949},{"x":0.07678245007991791,"y":0.2614259421825409},{"x":0.0018281536176800728,"y":0.009140759706497192},{"x":0.014625228941440582,"y":0.0018281340599060059},{"x":0.0840950608253479,"y":0.0018281340599060059},{"x":0.09323583543300629,"y":0.009140759706497192},{"x":0.12431444227695465,"y":0.11517366766929626}]],"circles":[],"shapes":[{"type":"POLYGON","vertices":[{"x":0.0822669118642807,"y":0.2742230296134949},{"x":0.1590493619441986,"y":0.2742230296134949},{"x":0.1736745834350586,"y":0.2669104039669037},{"x":0.20109689235687256,"y":0.177330881357193},{"x":0.21206581592559814,"y":0.162705659866333},{"x":0.23948810994625092,"y":0.2577696442604065},{"x":0.2522851824760437,"y":0.2742230296134949},{"x":0.325411319732666,"y":0.2742230296134949},{"x":0.33820840716362,"y":0.2669104039669037},{"x":0.4149908721446991,"y":0.012797057628631592},{"x":0.4113345444202423,"y":0.0018281340599060059},{"x":0.33820840716362,"y":0.0018281340599060059},{"x":0.325411319732666,"y":0.009140759706497192},{"x":0.29433271288871765,"y":0.11334551870822906},{"x":0.28702011704444885,"y":0.11334551870822906},{"x":0.2632541060447693,"y":0.029250457882881165},{"x":0.2468007355928421,"y":0.0018281340599060059},{"x":0.1736745834350586,"y":0.0018281340599060059},{"x":0.1608775109052658,"y":0.009140759706497192},{"x":0.13162705302238464,"y":0.10968920588493347},{"x":0.12431444227695465,"y":0.11517366766929626},{"x":0.09323583543300629,"y":0.009140759706497192},{"x":0.0840950608253479,"y":0.0018281340599060059},{"x":0.014625228941440582,"y":0.0018281340599060059},{"x":0.0018281536176800728,"y":0.009140759706497192},{"x":0.07678245007991791,"y":0.2614259421825409}]}]}],"dynamicObjects":[]}EDIT: Ok, I think I'm getting somewhere now, I edited the output of physics body editor and just took one set of points from the polygons array like this, and that did it, now it's colliding and bouncing on one little point. So now how do I output from Physics Body Editor to json that's already like this so it can be used in Phaser? Is there a better way?{ "shape2":[ { "shape": [0.29433271288871765,0.11334551870822906 , 0.325411319732666,0.009140759706497192 , 0.33820840716362,0.0018281340599060059 , 0.4113345444202423,0.0018281340599060059 , 0.4149908721446991,0.012797057628631592 , 0.33820840716362,0.2669104039669037 ] } ]}EDIT: Can anyone demonstrate a workflow for this? The files I export from Physics Body Editor load but when I am trying to load them like in the Load Polygon 1 and 2 in the P2 Physics examples, I am getting TypeError: data.shape is undefined. Is there something you need to do to use the files Physics Body Editor makes? I'm using physics body editor 2.9.2 EDIT: I figured out I can use PhysicsEditor through Wine and it exports files like the example. Is there an export option I need to use with Physics Body Editor I would like to use it but the files it exports don't seem to be right for Phaser? I'm marking this as solved for now, I'm fine with Wine, Physics Editor seems to be a little more advanced than Physics Body Editor anyways. Link to comment Share on other sites More sharing options...
Recommended Posts