Skip to content

Commit d5a7579

Browse files
committed
Added new Sleep component
1 parent b969dee commit d5a7579

2 files changed

Lines changed: 62 additions & 0 deletions

File tree

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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;

v3/src/physics/matter-js/components/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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

0 commit comments

Comments
 (0)