Box2d Collisions Made Easy (With Isogenic Engine)
Isogenic Engine's box2d component got a boost today by making it really super easy to handle collisions between entities.
Say you have your player entity:
var player = new IgeEntityBox2d()
.id('player');
You have some enemies too:
var enemy = new IgeEntityBox2d()
.id('enemy1')
.category('enemy');
You need to know when an enemy collides with your player. Using vanilla box2d you would register a contact listener, examine the contact for information about the two bodies that collided and then decide if a collision occurred.
In comparison with the new IGE update you can now do this:
player.on('collisionStart', '.enemy', function (contactData) {
// Do whatever you want here
});
You can also hook when a contact ends:
player.on('collisionEnd', '.enemy', function (contactData) {
// Do whatever you want here
});
You'll notice the '.enemy' selector in the call to "on()". This is the target selector that must match the entity being collided with for the event to fire. If you want to reference an entity via id instead of category, use the # symbol instead:
player.on('collisionStart', '#enemy1', function (contactData) {
// Do whatever you want here
});
Awesome! :) - Available now on the premium repo dev branch version 1.5.5.