mirror of
https://github.com/photonstorm/phaser
synced 2025-02-17 14:38:30 +00:00
Added new Sleep component
This commit is contained in:
parent
b969dee104
commit
d5a7579f26
2 changed files with 62 additions and 0 deletions
61
v3/src/physics/matter-js/components/Sleep.js
Normal file
61
v3/src/physics/matter-js/components/Sleep.js
Normal 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;
|
|
@ -9,6 +9,7 @@ module.exports = {
|
|||
Mass: require('./Mass'),
|
||||
Static: require('./Static'),
|
||||
Sensor: require('./Sensor'),
|
||||
Sleep: require('./Sleep'),
|
||||
Transform: require('./Transform'),
|
||||
Velocity: require('./Velocity')
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue