@@ -185,9 +185,26 @@ var Factory = new Class({
185185 return body ;
186186 } ,
187187
188- fromJSON : function ( x , y , data , options )
188+ /**
189+ * **This function is still in development**
190+ *
191+ * Creates a body using the supplied body data, as provided by a JSON file.
192+ *
193+ * @method Phaser.Physics.Matter.Factory#fromJSON
194+ * @since 3.22.0
195+ *
196+ * @param {number } x - The X coordinate of the body.
197+ * @param {number } y - The Y coordinate of the body.
198+ * @param {object } data - The body data object as parsed from the JSON body format.
199+ * @param {object } [options] - Optional Matter body configuration object, as passed to `Body.create`.
200+ * @param {boolean } [addToWorld=true] - Should the newly created body be immediately added to the World?
201+ *
202+ * @return {MatterJS.Body } A Matter JS Body.
203+ */
204+ fromJSON : function ( x , y , data , options , addToWorld )
189205 {
190206 if ( options === undefined ) { options = { } ; }
207+ if ( addToWorld === undefined ) { addToWorld = true ; }
191208
192209 var body ;
193210 var vertexSets = data . verts ;
@@ -208,7 +225,6 @@ var Factory = new Class({
208225 for ( var i = 0 ; i < vertexSets . length ; i ++ )
209226 {
210227 var part = Body . create ( {
211- _position : Vertices . centre ( vertexSets [ i ] ) ,
212228 vertices : vertexSets [ i ]
213229 } ) ;
214230
@@ -224,7 +240,10 @@ var Factory = new Class({
224240
225241 Body . setPosition ( body , { x : x , y : y } ) ;
226242
227- this . world . add ( body ) ;
243+ if ( addToWorld )
244+ {
245+ this . world . add ( body ) ;
246+ }
228247
229248 return body ;
230249 } ,
0 commit comments