@@ -8,6 +8,7 @@ var Bodies = require('../lib/factory/Bodies');
88var Body = require ( '../lib/body/Body' ) ;
99var GetFastValue = require ( '../../../utils/object/GetFastValue' ) ;
1010var PhysicsEditorParser = require ( '../PhysicsEditorParser' ) ;
11+ var Vertices = require ( '../lib/geometry/Vertices' ) ;
1112
1213/**
1314 * [description]
@@ -111,7 +112,11 @@ var SetBody = {
111112 }
112113
113114 this . body = body ;
114- this . body . gameObject = this ;
115+
116+ for ( var i = 0 ; i < body . parts . length ; i ++ )
117+ {
118+ body . parts [ i ] . gameObject = this ;
119+ }
115120
116121 var _this = this ;
117122
@@ -186,34 +191,50 @@ var SetBody = {
186191
187192 case 'polygon' :
188193 var sides = GetFastValue ( config , 'sides' , 5 ) ;
189- var pradius = GetFastValue ( config , 'radius' , Math . max ( bodyWidth , bodyHeight ) / 2 ) ;
190- body = Bodies . polygon ( bodyX , bodyY , sides , pradius , options ) ;
194+ var pRadius = GetFastValue ( config , 'radius' , Math . max ( bodyWidth , bodyHeight ) / 2 ) ;
195+ body = Bodies . polygon ( bodyX , bodyY , sides , pRadius , options ) ;
191196 break ;
192197
193198 case 'fromVertices' :
194199 case 'fromVerts' :
195- var verts = GetFastValue ( config , 'verts' , [ ] ) ;
196200
197- if ( this . body )
198- {
199- Body . setVertices ( this . body , verts ) ;
200- body = this . body ;
201- }
202- else
201+ var verts = GetFastValue ( config , 'verts' , null ) ;
202+
203+ if ( verts )
203204 {
204- var flagInternal = GetFastValue ( config , 'flagInternal' , false ) ;
205- var removeCollinear = GetFastValue ( config , 'removeCollinear' , 0.01 ) ;
206- var minimumArea = GetFastValue ( config , 'minimumArea' , 10 ) ;
207- body = Bodies . fromVertices ( bodyX , bodyY , verts , options , flagInternal , removeCollinear , minimumArea ) ;
205+ // Has the verts array come from Vertices.fromPath, or is it raw?
206+ if ( typeof verts === 'string' )
207+ {
208+ verts = Vertices . fromPath ( verts ) ;
209+ }
210+
211+ if ( this . body && ! this . body . hasOwnProperty ( 'temp' ) )
212+ {
213+ Body . setVertices ( this . body , verts ) ;
214+
215+ body = this . body ;
216+ }
217+ else
218+ {
219+ var flagInternal = GetFastValue ( config , 'flagInternal' , false ) ;
220+ var removeCollinear = GetFastValue ( config , 'removeCollinear' , 0.01 ) ;
221+ var minimumArea = GetFastValue ( config , 'minimumArea' , 10 ) ;
222+
223+ body = Bodies . fromVertices ( bodyX , bodyY , verts , options , flagInternal , removeCollinear , minimumArea ) ;
224+ }
208225 }
226+
209227 break ;
210228
211229 case 'fromPhysicsEditor' :
212230 body = PhysicsEditorParser . parseBody ( bodyX , bodyY , bodyWidth , bodyHeight , config ) ;
213231 break ;
214232 }
215233
216- this . setExistingBody ( body , config . addToWorld ) ;
234+ if ( body )
235+ {
236+ this . setExistingBody ( body , config . addToWorld ) ;
237+ }
217238
218239 return this ;
219240 }
0 commit comments