@@ -17,6 +17,8 @@ module Phaser.Physics.Advanced {
1717
1818 this . game = game ;
1919
20+ this . space = new Space ( ) ;
21+
2022 Manager . collision = new Collision ( ) ;
2123
2224 }
@@ -59,6 +61,92 @@ module Phaser.Physics.Advanced {
5961 public static bodyCounter : number = 0 ;
6062 public static jointCounter : number = 0 ;
6163 public static shapeCounter : number = 0 ;
64+
65+ public space : Space ;
66+ public lastTime : number = 0 ;
67+ public frameRateHz : number = 60 ;
68+ public timeDelta : number = 0 ;
69+ public paused : bool = false ;
70+ public step : bool = false ; // step through the simulation (i.e. per click)
71+ public velocityIterations : number = 8 ;
72+ public positionIterations : number = 4 ;
73+ public allowSleep : bool = true ;
74+ public warmStarting : bool = true ;
75+
76+ public update ( ) {
77+
78+ var time = Date . now ( ) ;
79+ var frameTime = ( time - this . lastTime ) / 1000 ;
80+ this . lastTime = time ;
81+
82+ // if rAf - why?
83+ frameTime = Math . floor ( frameTime * 60 + 0.5 ) / 60 ;
84+
85+ //if (!mouseDown)
86+ //{
87+ // var p = canvasToWorld(mousePosition);
88+ // var body = space.findBodyByPoint(p);
89+ // //domCanvas.style.cursor = body ? "pointer" : "default";
90+ //}
91+
92+ if ( ! this . paused || this . step )
93+ {
94+ var h = 1 / this . frameRateHz ;
95+
96+ this . timeDelta += frameTime ;
97+
98+ if ( this . step )
99+ {
100+ this . step = false ;
101+ this . timeDelta = h ;
102+ }
103+
104+ for ( var maxSteps = 4 ; maxSteps > 0 && this . timeDelta >= h ; maxSteps -- )
105+ {
106+ this . space . step ( h , this . velocityIterations , this . positionIterations , this . warmStarting , this . allowSleep ) ;
107+ this . timeDelta -= h ;
108+ }
109+
110+ if ( this . timeDelta > h )
111+ {
112+ this . timeDelta = 0 ;
113+ }
114+
115+ //if (sceneIndex < demoArr.length)
116+ //{
117+ // demo = demoArr[sceneIndex];
118+ // demo.runFrame();
119+ //}
120+ }
121+
122+ //frameCount++;
123+
124+ }
125+
126+
127+
128+
129+
130+
131+
132+
133+
134+
135+
136+
137+
138+
139+
140+
141+
142+
143+
144+
145+
146+
147+
148+
149+
62150
63151 public static pixelsToMeters ( value : number ) : number {
64152 return value * 0.02 ;
@@ -81,7 +169,7 @@ module Phaser.Physics.Advanced {
81169 }
82170
83171 public static inertiaForCircle ( mass , center , radius_outer , radius_inner ) {
84- return mass * ( ( radius_outer * radius_outer + radius_inner * radius_inner ) * 0.5 + center . lengthsq ( ) ) ;
172+ return mass * ( ( radius_outer * radius_outer + radius_inner * radius_inner ) * 0.5 + center . lengthSq ( ) ) ;
85173 }
86174
87175 public static areaForSegment ( a , b , radius ) {
0 commit comments