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.grabAreaEntities = engine.getNodes(GrabAreaNode);
+
this.physicalEntities.on('nodeAdded', (event) => {
World.add(this.engine.world, [event.node.body.body]);
World.remove(this.engine.world, [event.node.body.body]);
});
+
+ this.grabAreaEntities.on('nodeAdded', (event) => {
+
+ World.add(this.engine.world, [event.node.grabArea.area]);
+ });
+ this.grabAreaEntities.on('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;
}
/**
}
};
-