Famo.us Access To CollisionData Upon Collision Event
In the famo.us source I see that two things are emitted upon collision: the 'collision' string, and a variable called collisionData, like this: (physics/constraints/Collision.js, l
Solution 1:
Get the object from the return event object:
collision.on('collision', function(data) {
// do stuff
console.log('data', data);
console.log('target', data.target);
console.log('source', data.source);
});
The target
and source
returned are the particles of the body objects you attached to create collision.
Example Code here (not tested fully)
Just do something like the following to track a unique id of who bumped together.
// assuming your body is called body and body1 respectively
// also, this is just partial code.
var uniqueID = 0;
body.particle = new Circle({
radius: 50,
position: [x, y, 0]
});
body1.particle = new Circle({
radius: 50,
position: [x, y, 0]
});
body.particle.uniqueID = 'body' + uniqueID;
uniqueID += 1;
body1.particle.uniqueID = 'body' + uniqueID;
collision.on('collision', function(data) {
// do stuff
console.log('target id', data.target.uniqueID);
console.log('source id', data.source.uniqueID);
});
Post a Comment for "Famo.us Access To CollisionData Upon Collision Event"