@@ -1013,6 +1013,9 @@ var Body = new Class({
10131013 this . prev . x = this . x ;
10141014 this . prev . y = this . y ;
10151015 this . preRotation = this . rotation ;
1016+
1017+ this . prevVelocity . x = this . velocity . x ;
1018+ this . prevVelocity . y = this . velocity . y ;
10161019 } ,
10171020
10181021 /**
@@ -1036,24 +1039,17 @@ var Body = new Class({
10361039 var velocity = this . velocity ;
10371040 var position = this . position ;
10381041
1039- // Has it been woken up?
1040- if ( this . sleeping && ! velocity . equals ( this . prevVelocity ) )
1041- {
1042- if ( ( velocity . y < 0 && ! this . isBlockedUp ( ) ) || ( velocity . y > 0 && ! this . isBlockedDown ( ) ) )
1043- {
1044- this . wake ( ) ;
1045- }
1046- }
1047-
1048- if ( this . sleeping )
1049- {
1050- return ;
1051- }
1052-
10531042 if ( this . moves )
10541043 {
10551044 this . world . updateMotion ( this , delta ) ;
10561045
1046+ // Has it been woken up?
1047+
1048+ if ( this . sleeping && ! this . checkWake ( ) )
1049+ {
1050+ return ;
1051+ }
1052+
10571053 if ( this . collideWorldBounds && ! this . worldBlocked . none )
10581054 {
10591055 this . checkWorldRebound ( ) ;
@@ -1194,9 +1190,6 @@ var Body = new Class({
11941190 wasTouching . down = touching . down ;
11951191 wasTouching . left = touching . left ;
11961192 wasTouching . right = touching . right ;
1197-
1198- this . prevVelocity . x = this . velocity . x ;
1199- this . prevVelocity . y = this . velocity . y ;
12001193 } ,
12011194
12021195 snapToBlocker : function ( )
@@ -1301,11 +1294,33 @@ var Body = new Class({
13011294 return null ;
13021295 } ,
13031296
1297+ checkWake : function ( )
1298+ {
1299+ if ( ! this . sleeping )
1300+ {
1301+ return false ;
1302+ }
1303+
1304+ var velocity = this . velocity ;
1305+
1306+ if ( ( velocity . y < 0 && ! this . isBlockedUp ( ) ) || ( velocity . y > 0 && ! this . isBlockedDown ( ) ) )
1307+ {
1308+ console . log ( '%c' + this . gameObject . name + ' has woken ' , 'background-color: lime' ) ;
1309+
1310+ this . sleeping = false ;
1311+ this . _sleep = 0 ;
1312+
1313+ return true ;
1314+ }
1315+
1316+ return false ;
1317+ } ,
1318+
13041319 wake : function ( )
13051320 {
13061321 if ( this . sleeping )
13071322 {
1308- console . log ( '%c' + this . gameObject . name + 'has woken ' , 'background-color: lime' ) ;
1323+ console . log ( '%c' + this . gameObject . name + ' has woken ' , 'background-color: lime' ) ;
13091324
13101325 this . sleeping = false ;
13111326 this . _sleep = 0 ;
@@ -2084,6 +2099,11 @@ var Body = new Class({
20842099
20852100 this . speed = Math . sqrt ( x * x + y * y ) ;
20862101
2102+ if ( this . speed > 0 )
2103+ {
2104+ this . wake ( ) ;
2105+ }
2106+
20872107 return this ;
20882108 } ,
20892109
@@ -2106,6 +2126,11 @@ var Body = new Class({
21062126
21072127 this . speed = Math . sqrt ( vx * vx + vy * vy ) ;
21082128
2129+ if ( this . speed > 0 )
2130+ {
2131+ this . wake ( ) ;
2132+ }
2133+
21092134 return this ;
21102135 } ,
21112136
@@ -2128,6 +2153,11 @@ var Body = new Class({
21282153
21292154 this . speed = Math . sqrt ( vx * vx + vy * vy ) ;
21302155
2156+ if ( this . speed > 0 )
2157+ {
2158+ this . wake ( ) ;
2159+ }
2160+
21312161 return this ;
21322162 } ,
21332163
@@ -2563,15 +2593,25 @@ var Body = new Class({
25632593 if ( amount < 0 && worldCollision . up && this . y + amount < bounds . y )
25642594 {
25652595 diff = amount - ( ( this . y + amount ) - bounds . y ) ;
2566-
2596+
2597+ if ( diff !== 0 )
2598+ {
2599+ this . wake ( ) ;
2600+ }
2601+
25672602 this . setWorldBlockedUp ( true ) ;
25682603
25692604 return diff ;
25702605 }
25712606 else if ( amount > 0 && worldCollision . down && this . bottom + amount > bounds . bottom )
25722607 {
25732608 diff = amount - ( ( this . bottom + amount ) - bounds . bottom ) ;
2574-
2609+
2610+ if ( diff !== 0 )
2611+ {
2612+ this . wake ( ) ;
2613+ }
2614+
25752615 this . setWorldBlockedDown ( true ) ;
25762616
25772617 return diff ;
@@ -2598,6 +2638,11 @@ var Body = new Class({
25982638 }
25992639 }
26002640
2641+ if ( diff !== 0 )
2642+ {
2643+ this . wake ( ) ;
2644+ }
2645+
26012646 return diff ;
26022647 } ,
26032648
0 commit comments