88/// <reference path="Bounds.ts" />
99/// <reference path="Space.ts" />
1010/// <reference path="shapes/IShape.ts" />
11+ /// <reference path="shapes/Triangle.ts" />
12+ /// <reference path="shapes/Circle.ts" />
13+ /// <reference path="shapes/Box.ts" />
14+ /// <reference path="shapes/Poly.ts" />
15+ /// <reference path="shapes/Segment.ts" />
1116
1217/**
1318* Phaser - Advanced Physics - Body
@@ -29,12 +34,12 @@ module Phaser.Physics.Advanced {
2934 {
3035 this . sprite = sprite ;
3136 this . game = sprite . game ;
32- this . position = new Phaser . Vec2 ( sprite . x , sprite . y ) ;
37+ this . position = new Phaser . Vec2 ( Phaser . Physics . Advanced . Manager . pixelsToMeters ( sprite . x ) , Phaser . Physics . Advanced . Manager . pixelsToMeters ( sprite . y ) ) ;
3338 this . angle = sprite . rotation ;
3439 }
3540 else
3641 {
37- this . position = new Phaser . Vec2 ( x , y ) ;
42+ this . position = new Phaser . Vec2 ( Phaser . Physics . Advanced . Manager . pixelsToMeters ( x ) , Phaser . Physics . Advanced . Manager . pixelsToMeters ( y ) ) ;
3843 this . angle = 0 ;
3944 }
4045
@@ -64,6 +69,8 @@ module Phaser.Physics.Advanced {
6469
6570 }
6671
72+ private _tempVec2 : Phaser . Vec2 = new Phaser . Vec2 ;
73+
6774 /**
6875 * Reference to Phaser.Game
6976 */
@@ -139,6 +146,11 @@ module Phaser.Physics.Advanced {
139146 // Bounds of all shapes
140147 public bounds : Bounds ;
141148
149+ public mass : number ;
150+ public massInverted : number ;
151+ public inertia : number ;
152+ public inertiaInverted : number ;
153+
142154 public fixedRotation = false ;
143155 public categoryBits = 0x0001 ;
144156 public maskBits = 0xFFFF ;
@@ -195,6 +207,62 @@ module Phaser.Physics.Advanced {
195207
196208 }
197209
210+ public addPoly ( verts , elasticity ?: number = 1 , friction ?: number = 1 , density ?: number = 1 ) : Phaser . Physics . Advanced . Shapes . Poly {
211+
212+ var poly : Phaser . Physics . Advanced . Shapes . Poly = new Phaser . Physics . Advanced . Shapes . Poly ( verts ) ;
213+ poly . elasticity = elasticity ;
214+ poly . friction = friction ;
215+ poly . density = density ;
216+
217+ this . addShape ( poly ) ;
218+ this . resetMassData ( ) ;
219+
220+ return poly ;
221+
222+ }
223+
224+ public addTriangle ( x1 : number , y1 : number , x2 : number , y2 : number , x3 : number , y3 : number , elasticity ?: number = 1 , friction ?: number = 1 , density ?: number = 1 ) : Phaser . Physics . Advanced . Shapes . Triangle {
225+
226+ var tri : Phaser . Physics . Advanced . Shapes . Triangle = new Phaser . Physics . Advanced . Shapes . Triangle ( x1 , y1 , x2 , y2 , x3 , y3 ) ;
227+ tri . elasticity = elasticity ;
228+ tri . friction = friction ;
229+ tri . density = density ;
230+
231+ this . addShape ( tri ) ;
232+ this . resetMassData ( ) ;
233+
234+ return tri ;
235+
236+ }
237+
238+ public addBox ( x : number , y : number , width : number , height : number , elasticity ?: number = 1 , friction ?: number = 1 , density ?: number = 1 ) : Phaser . Physics . Advanced . Shapes . Box {
239+
240+ var box : Phaser . Physics . Advanced . Shapes . Box = new Phaser . Physics . Advanced . Shapes . Box ( x , y , width , height ) ;
241+ box . elasticity = elasticity ;
242+ box . friction = friction ;
243+ box . density = density ;
244+
245+ this . addShape ( box ) ;
246+ this . resetMassData ( ) ;
247+
248+ return box ;
249+
250+ }
251+
252+ public addCircle ( radius : number , x ?: number = 0 , y ?: number = 0 , elasticity ?: number = 1 , friction ?: number = 1 , density ?: number = 1 ) : Phaser . Physics . Advanced . Shapes . Circle {
253+
254+ var circle : Phaser . Physics . Advanced . Shapes . Circle = new Phaser . Physics . Advanced . Shapes . Circle ( radius , x , y ) ;
255+ circle . elasticity = elasticity ;
256+ circle . friction = friction ;
257+ circle . density = density ;
258+
259+ this . addShape ( circle ) ;
260+ this . resetMassData ( ) ;
261+
262+ return circle ;
263+
264+ }
265+
198266 public addShape ( shape ) {
199267
200268 // Check not already part of this body
@@ -218,10 +286,6 @@ module Phaser.Physics.Advanced {
218286
219287 }
220288
221- public mass : number ;
222- public massInverted : number ;
223- public inertia : number ;
224- public inertiaInverted : number ;
225289
226290 private setMass ( mass ) {
227291
@@ -381,7 +445,6 @@ module Phaser.Physics.Advanced {
381445
382446 }
383447
384- private _tempVec2 : Phaser . Vec2 = new Phaser . Vec2 ;
385448
386449 public updateVelocity ( gravity , dt , damping ) {
387450
0 commit comments