aboutsummaryrefslogtreecommitdiff
path: root/lib/systems/physics_world_control.js
diff options
context:
space:
mode:
authorRubén Beltrán del Río <ben@nsovocal.com>2018-05-28 21:35:38 -0500
committerGitHub <noreply@github.com>2018-05-28 21:35:38 -0500
commit1676911c8a2621274bf75ff7271faa926cf58d6c (patch)
tree776613e919a5fae242ba65f0871028d4c678bcff /lib/systems/physics_world_control.js
parent764ac76aa90b75cd5d79c217220654a6975069af (diff)
Add Grab System (#9)
* Remove unused code * Adds grab components * Adds grab nodes * Add sensors to the physics world * Add grab systems * Add new sprites * Attach grab components * Add grab system to engine * Update changelog
Diffstat (limited to 'lib/systems/physics_world_control.js')
-rw-r--r--lib/systems/physics_world_control.js17
1 files changed, 16 insertions, 1 deletions
diff --git a/lib/systems/physics_world_control.js b/lib/systems/physics_world_control.js
index a658d5c..370701e 100644
--- a/lib/systems/physics_world_control.js
+++ b/lib/systems/physics_world_control.js
@@ -2,6 +2,7 @@ import { System } from '@serpentity/serpentity';
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.'
@@ -56,6 +57,8 @@ export default class PhysicsWorldControlSystem extends System {
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]);
@@ -64,6 +67,15 @@ export default class PhysicsWorldControlSystem extends System {
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]);
+ });
}
/**
@@ -78,6 +90,10 @@ export default class PhysicsWorldControlSystem extends System {
this.physicalEntities.removeAllListeners('nodeAdded');
this.physicalEntities.removeAllListeners('nodeRemoved');
this.physicalEntities = null;
+
+ this.grabAreaEntities.removeAllListeners('nodeAdded');
+ this.grabAreaEntities.removeAllListeners('nodeRemoved');
+ this.grabAreaEntities = null;
}
/**
@@ -95,4 +111,3 @@ export default class PhysicsWorldControlSystem extends System {
}
};
-