Added new Sleep component

This commit is contained in:
Richard Davey 2017-11-22 14:12:57 +00:00
parent b969dee104
commit d5a7579f26
2 changed files with 62 additions and 0 deletions

View file

@ -0,0 +1,61 @@
var MatterEvents = require('../lib/core/Events');
var PhysicsEvent = require('../events/');
var Sleep = {
setSleepThreshold: function (value)
{
if (value === undefined) { value = 60; }
this.body.sleepThreshold = value;
return this;
},
setSleepEvents: function (start, end)
{
this.setSleepStartEvent(start);
this.setSleepEndEvent(end);
return this;
},
setSleepStartEvent: function (value)
{
if (value)
{
var worldEvents = this.world.events;
MatterEvents.on(this.body, 'sleepStart', function (event) {
worldEvents.dispatch(new PhysicsEvent.SLEEP_START(event, this));
});
}
else
{
MatterEvents.off(this.body, 'sleepStart');
}
return this;
},
setSleepEndEvent: function (value)
{
if (value)
{
var worldEvents = this.world.events;
MatterEvents.on(this.body, 'sleepEnd', function (event) {
worldEvents.dispatch(new PhysicsEvent.SLEEP_END(event, this));
});
}
else
{
MatterEvents.off(this.body, 'sleepEnd');
}
return this;
}
};
module.exports = Sleep;

View file

@ -9,6 +9,7 @@ module.exports = {
Mass: require('./Mass'),
Static: require('./Static'),
Sensor: require('./Sensor'),
Sleep: require('./Sleep'),
Transform: require('./Transform'),
Velocity: require('./Velocity')