1 decade ago by MobileMark
I've figured out how to detect collisions by using m_userdata in the entity , but I'm still having trouble with consistency
heres the code I'm using
Basically when the entity hits the ground its animation is supposed to change, but when there are two of the same entity I get an undefined error for ig.game.entities[valInd].currentAnim even though with one entity it works.
I'm very confused as to what the proper way to detect collisions is in Box2D, any help would be greatly appreciated :)
heres the code I'm using
myListenerClass.prototype.Add = function( points ) { var body1 = points.shape1.GetBody(); var body2 = points.shape2.GetBody(); var body1val=body1.m_userData!=null?body1.m_userData.indexOf("GHOST||"):null; var body2val=body2.m_userData!=null?body2.m_userData.indexOf("GHOST||"):null; if(body1val>-1&&body2.m_userData==null||body2val>-1&&body1.m_userData==null) { if(body1val!=null&&body1val>-1) {var valInd=parseInt(body1.m_userData.split("GHOST||")[1])-1;} else {var valInd=parseInt(body2.m_userData.split("GHOST||")[1])-1;} if(ig.game.entities[valInd]) { if(ig.game.entities[valInd].currentAnim == ig.game.entities[valInd].anims.dead) {} else {ig.game.entities[valInd].currentAnim = ig.game.entities[valInd].anims.dead;} } } }; var myListener = new myListenerClass(this.body.m_userData); ig.world.SetContactListener( myListener );
Basically when the entity hits the ground its animation is supposed to change, but when there are two of the same entity I get an undefined error for ig.game.entities[valInd].currentAnim even though with one entity it works.
I'm very confused as to what the proper way to detect collisions is in Box2D, any help would be greatly appreciated :)