@@ -221,8 +221,8 @@ Phaser.Physics.Arcade.prototype = {
221221
222222 if ( body . allowGravity )
223223 {
224- this . _gravityX = ( this . gravity . x + body . gravity . x ) ;
225- this . _gravityY = ( this . gravity . y + body . gravity . y ) ;
224+ this . _gravityX = ( this . gravity . x + body . gravity . x ) * this . game . time . physicsElapsed ;
225+ this . _gravityY = ( this . gravity . y + body . gravity . y ) * this . game . time . physicsElapsed ;
226226 }
227227 else
228228 {
@@ -236,61 +236,22 @@ Phaser.Physics.Arcade.prototype = {
236236 // body.rotation += (body.angularVelocity * this.game.time.physicsElapsed);
237237 // body.angularVelocity += this._velocityDelta;
238238
239- // body.motionVelocity.x = (this.computeVelocity(body, body.velocity.x, body.acceleration.x, body.drag.x, body.maxVelocity.x, this._gravityX) - body.velocity.x) * 0.5;
240- // body.motionVelocity.y = (this.computeVelocity(body, body.velocity.y, body.acceleration.y, body.drag.y, body.maxVelocity.y, this._gravityY) - body.velocity.y) * 0.5;
241-
242239 // velocity = velocity + gravity*delta_time/2
243240 // position = position + velocity*delta_time
244241 // velocity = velocity + gravity*delta_time/2
245242
243+ body . velocity . x += this . _gravityX ;
244+ body . velocity . y += this . _gravityY ;
245+
246+ body . motionVelocity . x = body . acceleration . x * this . game . time . physicsElapsed ;
247+ body . motionVelocity . y = body . acceleration . y * this . game . time . physicsElapsed ;
248+
246249 // temp = acc*dt
247250 // pos = pos + dt*(vel + temp/2)
248251 // vel = vel + temp
249252
250- this . _drag = 0 ;
251-
252- if ( body . drag . x !== 0 && body . velocity . x !== 0 && body . acceleration . x === 0 )
253- {
254- if ( body . velocity . x - body . drag . x > 0 )
255- {
256- this . _drag = - body . drag . x ;
257- }
258- else if ( body . velocity . x + body . drag . x < 0 )
259- {
260- this . _drag = body . drag . x ;
261- }
262- }
263-
264- // body.motionVelocity.x = body.acceleration.x + this._gravityX - body.drag.x * this.game.time.physicsElapsed;
265- // body.motionVelocity.x = body.acceleration.x + this._gravityX * this.game.time.physicsElapsed;
266- body . motionVelocity . x = ( body . acceleration . x + this . _gravityX + this . _drag ) * this . game . time . physicsElapsed ;
267-
268- this . _drag = 0 ;
269-
270- if ( body . drag . y !== 0 && body . velocity . y !== 0 && body . acceleration . y === 0 )
271- {
272- if ( body . velocity . y - body . drag . y > 0 )
273- {
274- this . _drag = - body . drag . y ;
275- }
276- else if ( body . velocity . y + body . drag . y < 0 )
277- {
278- this . _drag = body . drag . y ;
279- }
280- }
281-
282- // body.motionVelocity.y = body.acceleration.y + this._gravityY - body.drag.y * this.game.time.physicsElapsed;
283- // body.motionVelocity.y = body.acceleration.y + this._gravityY * this.game.time.physicsElapsed;
284- body . motionVelocity . y = ( body . acceleration . y + this . _gravityY + this . _drag ) * this . game . time . physicsElapsed ;
285-
286- // if (body.sleeping === false)
287- // {
288- // body.x = body.x + this.game.time.physicsElapsed * (body.velocity.x + body.motionVelocity.x / 2);
289- // body.velocity.x = body.velocity.x + body.motionVelocity.x;
290-
291- // body.y = body.y + this.game.time.physicsElapsed * (body.velocity.y + body.motionVelocity.y / 2);
292- // body.velocity.y = body.velocity.y + body.motionVelocity.y;
293- // }
253+ // body.motionVelocity.x = (body.acceleration.x + this._gravityX) * this.game.time.physicsElapsed;
254+ // body.motionVelocity.y = (body.acceleration.y + this._gravityY) * this.game.time.physicsElapsed;
294255
295256 } ,
296257
@@ -306,11 +267,11 @@ Phaser.Physics.Arcade.prototype = {
306267 * @param {number } gravity - The acceleration due to gravity. Gravity will not induce drag.
307268 * @return {number } The altered Velocity value.
308269 */
309- computeVelocity : function ( body , velocity , acceleration , drag , max ) {
270+ computeVelocity : function ( body , velocity , acceleration , drag , max , gravity ) {
310271
311272 max = max || 10000 ;
312273
313- velocity += acceleration ;
274+ velocity += ( acceleration + gravity ) * this . game . time . physicsElapsed ;
314275
315276 if ( acceleration === 0 && drag !== 0 )
316277 {
@@ -330,15 +291,6 @@ Phaser.Physics.Arcade.prototype = {
330291 }
331292 }
332293
333- if ( velocity > max )
334- {
335- velocity = max ;
336- }
337- else if ( velocity < - max )
338- {
339- velocity = - max ;
340- }
341-
342294 return velocity ;
343295
344296 } ,
0 commit comments