@@ -135,9 +135,9 @@ Phaser.Physics.Arcade.Body = function (sprite) {
135135 this . angle = 0 ;
136136
137137 /**
138- * @property {number } minBounceVelocity - The minimum bounce velocity (could just be the bounce value?) .
138+ * @property {number } minBounceVelocity - Optional minimum bounce velocity.
139139 */
140- this . minBounceVelocity = 0.5 ;
140+ this . minBounceVelocity = 0.1 ;
141141
142142 /**
143143 * @property {Phaser.Point } gravity - The gravity applied to the motion of the Body. This works in addition to any gravity set on the world.
@@ -477,6 +477,38 @@ Phaser.Physics.Arcade.Body.prototype = {
477477
478478 } ,
479479
480+ /**
481+ * Internal method used to check the Body against the World Bounds.
482+ *
483+ * @method Phaser.Physics.Arcade#adjustWorldBounds
484+ * @protected
485+ */
486+ adjustWorldBounds : function ( ) {
487+
488+ if ( this . x < this . game . world . bounds . x )
489+ {
490+ this . x += this . game . world . bounds . x - this . x ;
491+ this . preX += this . game . world . bounds . x - this . x ;
492+ }
493+ else if ( this . right > this . game . world . bounds . right )
494+ {
495+ this . x -= this . right - this . game . world . bounds . right ;
496+ this . preX -= this . right - this . game . world . bounds . right ;
497+ }
498+
499+ if ( this . y < this . game . world . bounds . y )
500+ {
501+ this . y += this . game . world . bounds . y - this . y ;
502+ this . preY += this . game . world . bounds . y - this . y ;
503+ }
504+ else if ( this . bottom > this . game . world . bounds . bottom )
505+ {
506+ this . y -= this . bottom - this . game . world . bounds . bottom ;
507+ this . preY -= this . bottom - this . game . world . bounds . bottom ;
508+ }
509+
510+ } ,
511+
480512 /**
481513 * Internal method.
482514 *
@@ -510,16 +542,16 @@ Phaser.Physics.Arcade.Body.prototype = {
510542
511543 this . _dx = this . game . time . physicsElapsed * ( this . velocity . x + this . motionVelocity . x / 2 ) ;
512544
513- if ( this . _dx > this . minBounceVelocity || this . getTotalGravityX ( ) > 0 )
514- {
545+ // if (this._dx > this.minBounceVelocity || this.getTotalGravityX() > 0)
546+ // {
515547 this . x += this . _dx ;
516548 this . velocity . x += this . motionVelocity . x ;
517- }
518- else
519- {
520- this . preX = this . x ;
521- this . velocity . x = 0 ;
522- }
549+ // }
550+ // else
551+ // {
552+ // this.preX = this.x;
553+ // this.velocity.x = 0;
554+ // }
523555 }
524556 else if ( this . blocked . right && this . blockedPoint . x > 0 )
525557 {
@@ -530,16 +562,16 @@ Phaser.Physics.Arcade.Body.prototype = {
530562
531563 this . _dx = this . game . time . physicsElapsed * ( this . velocity . x + this . motionVelocity . x / 2 ) ;
532564
533- if ( this . _dx < - this . minBounceVelocity || this . getTotalGravityX ( ) < 0 )
534- {
565+ // if (this._dx < -this.minBounceVelocity || this.getTotalGravityX() < 0)
566+ // {
535567 this . x += this . _dx ;
536568 this . velocity . x += this . motionVelocity . x ;
537- }
538- else
539- {
540- this . preX = this . x ;
541- this . velocity . x = 0 ;
542- }
569+ // }
570+ // else
571+ // {
572+ // this.preX = this.x;
573+ // this.velocity.x = 0;
574+ // }
543575 }
544576 else
545577 {
@@ -557,16 +589,16 @@ Phaser.Physics.Arcade.Body.prototype = {
557589
558590 this . _dy = this . game . time . physicsElapsed * ( this . velocity . y + this . motionVelocity . y / 2 ) ;
559591
560- if ( this . _dy > this . minBounceVelocity || this . getTotalGravityY ( ) > 0 )
561- {
592+ // if (this._dy > this.minBounceVelocity || this.getTotalGravityY() > 0)
593+ // {
562594 this . y += this . _dy ;
563595 this . velocity . y += this . motionVelocity . y ;
564- }
565- else
566- {
567- this . preY = this . y ;
568- this . velocity . y = 0 ;
569- }
596+ // }
597+ // else
598+ // {
599+ // this.preY = this.y;
600+ // this.velocity.y = 0;
601+ // }
570602 }
571603 else if ( this . blocked . down && this . blockedPoint . y > 0 )
572604 {
@@ -577,16 +609,16 @@ Phaser.Physics.Arcade.Body.prototype = {
577609
578610 this . _dy = this . game . time . physicsElapsed * ( this . velocity . y + this . motionVelocity . y / 2 ) ;
579611
580- if ( this . _dy < - this . minBounceVelocity || this . getTotalGravityY ( ) < 0 )
581- {
612+ // if (this._dy < -this.minBounceVelocity || this.getTotalGravityY() < 0)
613+ // {
582614 this . y += this . _dy ;
583615 this . velocity . y += this . motionVelocity . y ;
584- }
585- else
586- {
587- this . preY = this . y ;
588- this . velocity . y = 0 ;
589- }
616+ // }
617+ // else
618+ // {
619+ // this.preY = this.y;
620+ // this.velocity.y = 0;
621+ // }
590622 }
591623 else
592624 {
@@ -1164,7 +1196,7 @@ Phaser.Physics.Arcade.Body.prototype = {
11641196 } ,
11651197
11661198 /**
1167- * Internal method. This is called directly before the sprites are sent to the renderer.
1199+ * Internal method. This is called directly before the sprites are sent to the renderer and after the update function has finished .
11681200 *
11691201 * @method Phaser.Physics.Arcade#postUpdate
11701202 * @protected
@@ -1173,6 +1205,8 @@ Phaser.Physics.Arcade.Body.prototype = {
11731205
11741206 if ( this . moves )
11751207 {
1208+ this . adjustWorldBounds ( ) ;
1209+
11761210 if ( this . deltaX ( ) < 0 )
11771211 {
11781212 this . facing = Phaser . LEFT ;
0 commit comments