import { Engine, World } from 'matter-js';
import PhysicalNode from '../nodes/physical';
+import GrabAreaNode from '../nodes/grab_area';
const internals = {
kNoEngine: 'No matter js physics engine found. Make sure you set the `engine` key in the config object when initializing.'
added(engine) {
this.physicalEntities = engine.getNodes(PhysicalNode);
- this.physicalEntities.on('nodeAdded', (event) => {
+ this.grabAreaEntities = engine.getNodes(GrabAreaNode);
+
+ this.physicalEntities.addEventListener('nodeAdded', (event) => {
World.add(this.engine.world, [event.node.body.body]);
});
- this.physicalEntities.on('nodeRemoved', (event) => {
+ this.physicalEntities.addEventListener('nodeRemoved', (event) => {
World.remove(this.engine.world, [event.node.body.body]);
});
+
+ this.grabAreaEntities.addEventListener('nodeAdded', (event) => {
+
+ World.add(this.engine.world, [event.node.grabArea.area]);
+ });
+ this.grabAreaEntities.addEventListener('nodeRemoved', (event) => {
+
+ World.remove(this.engine.world, [event.node.grabArea.area]);
+ });
}
/**
this.physicalEntities.removeAllListeners('nodeAdded');
this.physicalEntities.removeAllListeners('nodeRemoved');
this.physicalEntities = null;
+
+ this.grabAreaEntities.removeAllListeners('nodeAdded');
+ this.grabAreaEntities.removeAllListeners('nodeRemoved');
+ this.grabAreaEntities = null;
}
/**
Engine.update(this.engine, currentFrameDuration);
}
-};
-
+}