@@ -315,7 +315,7 @@ Phaser.Physics.Arcade.Body = function (sprite) {
315315 this . _sleepTimer = 0 ; // ms
316316 this . _drag = 0 ;
317317 this . _debug = 0 ;
318- // this.friction = 0.99 ;
318+ this . friction = 0.9 ;
319319 // this._debug = 0;
320320
321321 /**
@@ -387,7 +387,7 @@ Phaser.Physics.Arcade.Body.prototype = {
387387 this . preY = ( this . sprite . world . y - ( this . sprite . anchor . y * this . height ) ) + this . offset . y ;
388388 this . preRotation = this . sprite . angle ;
389389
390- if ( this . canSleep && this . sleeping && this . velocity . equals ( this . prevVelocity ) === false )
390+ if ( this . canSleep && this . sleeping && ( this . velocity . equals ( this . prevVelocity ) === false || this . acceleration . isZero ( ) === false ) )
391391 {
392392 this . sleeping = false ;
393393 this . _sleepTimer = 0 ;
@@ -450,33 +450,19 @@ Phaser.Physics.Arcade.Body.prototype = {
450450
451451 applyMotion : function ( ) {
452452
453- // Apply drag - this should be proportionally applied, not linearly like below
454- if ( this . drag . x !== 0 && this . acceleration . x === 0 )
453+ if ( this . friction > 0 && this . acceleration . isZero ( ) )
455454 {
456- this . _drag = this . drag . x * this . game . time . physicsElapsed ;
457-
458- if ( this . velocity . x > 0 )
455+ if ( this . speed > this . friction )
459456 {
460- this . velocity . x -= this . _drag ;
457+ this . speed -= this . friction ;
461458 }
462- else if ( this . velocity . x < 0 )
459+ else
463460 {
464- this . velocity . x += this . _drag ;
461+ this . speed = 0 ;
465462 }
466- }
467-
468- if ( this . drag . y !== 0 && this . acceleration . y === 0 )
469- {
470- this . _drag = this . drag . y * this . game . time . physicsElapsed ;
471463
472- if ( this . velocity . y > 0 )
473- {
474- this . velocity . y -= this . _drag ;
475- }
476- else if ( this . velocity . y < 0 )
477- {
478- this . velocity . y += this . _drag ;
479- }
464+ this . velocity . x = Math . cos ( this . angle ) * this . speed ;
465+ this . velocity . y = Math . sin ( this . angle ) * this . speed ;
480466 }
481467
482468 this . x += this . game . time . physicsElapsed * ( this . velocity . x + this . motionVelocity . x / 2 ) ;
@@ -485,74 +471,22 @@ Phaser.Physics.Arcade.Body.prototype = {
485471 this . y += this . game . time . physicsElapsed * ( this . velocity . y + this . motionVelocity . y / 2 ) ;
486472 this . velocity . y += this . motionVelocity . y ;
487473
488-
489- /*
490- if (this.drag.x !== 0 && this.acceleration.x === 0)
491- {
492- this._drag = this.drag.x * this.game.time.physicsElapsed;
493-
494- if (this.velocity.x - this._drag > 0)
495- {
496- this.velocity.x -= this._drag;
497- this.x += this.game.time.physicsElapsed * (this.velocity.x + this.motionVelocity.x / 2);
498- this.velocity.x += this.motionVelocity.x;
499- }
500- else if (this.velocity.x + this.drag.x < 0)
501- {
502- this.velocity.x += this._drag;
503- this.x += this.game.time.physicsElapsed * (this.velocity.x + this.motionVelocity.x / 2);
504- this.velocity.x += this.motionVelocity.x;
505- }
506- else
507- {
508- this.velocity.x = 0;
509- // this.preX = this.x;
510- // this.motionVelocity.x = 0;
511- }
512- }
513- else
514- {
515- this.x += this.game.time.physicsElapsed * (this.velocity.x + this.motionVelocity.x / 2);
516- this.velocity.x += this.motionVelocity.x;
517- }
518-
519- if (this.drag.y !== 0 && this.acceleration.y === 0)
474+ if ( this . velocity . x > this . maxVelocity . x )
520475 {
521- this._drag = this.drag.y * this.game.time.physicsElapsed;
522-
523- if (this.velocity.y - this._drag > 0)
524- {
525- this.velocity.y -= this._drag;
526- this.y += this.game.time.physicsElapsed * (this.velocity.y + this.motionVelocity.y / 2);
527- this.velocity.y += this.motionVelocity.y;
528- }
529- else if (this.velocity.y + this.drag.y < 0)
530- {
531- this.velocity.y += this._drag;
532- this.y += this.game.time.physicsElapsed * (this.velocity.y + this.motionVelocity.y / 2);
533- this.velocity.y += this.motionVelocity.y;
534- }
535- else
536- {
537- this.velocity.y = 0;
538- // this.preY = this.y;
539- // this.motionVelocity.y = 0;
540- }
476+ this . velocity . x = this . maxVelocity . x ;
541477 }
542- else
478+ else if ( this . velocity . x < - this . maxVelocity . x )
543479 {
544- this.y += this.game.time.physicsElapsed * (this.velocity.y + this.motionVelocity.y / 2);
545- this.velocity.y += this.motionVelocity.y;
480+ this . velocity . x = - this . maxVelocity . x ;
546481 }
547- */
548482
549- if ( this . velocity . x > this . maxVelocity . x )
483+ if ( this . velocity . y > this . maxVelocity . y )
550484 {
551- // this.velocity.x = this.maxVelocity.x ;
485+ this . velocity . y = this . maxVelocity . y ;
552486 }
553- else if ( this . velocity . x < - this . maxVelocity . x )
487+ else if ( this . velocity . y < - this . maxVelocity . y )
554488 {
555- // this.velocity.x = -this.maxVelocity.x ;
489+ this . velocity . y = - this . maxVelocity . y ;
556490 }
557491
558492 if ( this . collideWorldBounds )
@@ -606,7 +540,7 @@ Phaser.Physics.Arcade.Body.prototype = {
606540
607541 if ( this . collideWorldBounds )
608542 {
609- // this.checkWorldBounds();
543+ this . checkWorldBounds ( ) ;
610544 }
611545
612546 this . center . setTo ( this . x + this . halfWidth , this . y + this . halfHeight ) ;
0 commit comments