Skip to content

Commit 0d66c98

Browse files
committed
Added JSDocs for fromPhysicsEditor method and tidied things up a bit.
1 parent ea338ca commit 0d66c98

1 file changed

Lines changed: 41 additions & 3 deletions

File tree

src/physics/matter-js/Factory.js

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,49 @@ var Factory = new Class({
198198
return body;
199199
},
200200

201-
fromPhysicsEditor: function (x, y, width, height, config)
201+
/**
202+
* Creates a body using data exported from the application PhysicsEditor (https://www.codeandweb.com/physicseditor)
203+
*
204+
* The PhysicsEditor file should be loaded as JSON:
205+
*
206+
* ```javascript
207+
* preload ()
208+
* {
209+
* this.load.json('vehicles', 'assets/vehicles.json);
210+
* }
211+
*
212+
* create ()
213+
* {
214+
* const vehicleShapes = this.cache.json.get('vehicles');
215+
* this.matter.add.fromPhysicsEditor(400, 300, vehicleShapes.truck);
216+
* }
217+
* ```
218+
*
219+
* Do not pass the entire JSON file to this method, but instead pass one of the shapes contained within it.
220+
*
221+
* If you pas in an `options` object, any settings in there will override those in the PhysicsEditor config object.
222+
*
223+
* @method Phaser.Physics.Matter.Factory#fromPhysicsEditor
224+
* @since 3.22.0
225+
*
226+
* @param {number} x - The horizontal world location of the body.
227+
* @param {number} y - The vertical world location of the body.
228+
* @param {any} config - The JSON data exported from PhysicsEditor.
229+
* @param {Phaser.Types.Physics.Matter.MatterBodyConfig} [options] - An optional Body configuration object that is used to set initial Body properties on creation.
230+
* @param {boolean} [addToWorld=true] - Should the newly created body be immediately added to the World?
231+
*
232+
* @return {MatterJS.Body} A Matter JS Body.
233+
*/
234+
fromPhysicsEditor: function (x, y, config, options, addToWorld)
202235
{
203-
var body = PhysicsEditorParser.parseBody(x, y, width, height, config);
236+
if (addToWorld === undefined) { addToWorld = true; }
237+
238+
var body = PhysicsEditorParser.parseBody(x, y, config, options);
204239

205-
// this.world.add(body);
240+
if (addToWorld && !this.world.has(body))
241+
{
242+
this.world.add(body);
243+
}
206244

207245
return body;
208246
},

0 commit comments

Comments
 (0)