File tree Expand file tree Collapse file tree
v3/src/physics/matter-js/components Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ var MatterEvents = require ( '../lib/core/Events' ) ;
2+ var PhysicsEvent = require ( '../events/' ) ;
3+
4+ var Sleep = {
5+
6+ setSleepThreshold : function ( value )
7+ {
8+ if ( value === undefined ) { value = 60 ; }
9+
10+ this . body . sleepThreshold = value ;
11+
12+ return this ;
13+ } ,
14+
15+ setSleepEvents : function ( start , end )
16+ {
17+ this . setSleepStartEvent ( start ) ;
18+ this . setSleepEndEvent ( end ) ;
19+
20+ return this ;
21+ } ,
22+
23+ setSleepStartEvent : function ( value )
24+ {
25+ if ( value )
26+ {
27+ var worldEvents = this . world . events ;
28+
29+ MatterEvents . on ( this . body , 'sleepStart' , function ( event ) {
30+ worldEvents . dispatch ( new PhysicsEvent . SLEEP_START ( event , this ) ) ;
31+ } ) ;
32+ }
33+ else
34+ {
35+ MatterEvents . off ( this . body , 'sleepStart' ) ;
36+ }
37+
38+ return this ;
39+ } ,
40+
41+ setSleepEndEvent : function ( value )
42+ {
43+ if ( value )
44+ {
45+ var worldEvents = this . world . events ;
46+
47+ MatterEvents . on ( this . body , 'sleepEnd' , function ( event ) {
48+ worldEvents . dispatch ( new PhysicsEvent . SLEEP_END ( event , this ) ) ;
49+ } ) ;
50+ }
51+ else
52+ {
53+ MatterEvents . off ( this . body , 'sleepEnd' ) ;
54+ }
55+
56+ return this ;
57+ }
58+
59+ } ;
60+
61+ module . exports = Sleep ;
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ module.exports = {
99 Mass : require ( './Mass' ) ,
1010 Static : require ( './Static' ) ,
1111 Sensor : require ( './Sensor' ) ,
12+ Sleep : require ( './Sleep' ) ,
1213 Transform : require ( './Transform' ) ,
1314 Velocity : require ( './Velocity' )
1415
You can’t perform that action at this time.
0 commit comments