Checking for collisions among bodies
In the previous chapter, to check for collision, we iterated through idol contact points to see when it hit the ground.
Both Box2D and Chipmunk2D have more interesting ways to check for collisions, as they handle collision listeners.
Add the highlighted line to the init
function:
init:function () { this._super(); var backgroundLayer = cc.LayerGradient.create(cc.color(0xdf,0x9f,0x83,255), cc.color(0xfa,0xf7,0x9f,255)); this.addChild(backgroundLayer); world = new cp.Space(); world.gravity = cp.v(0, -100); this._debugNode = cc.PhysicsDebugNode.create(world); this._debugNode.setVisible( true ); this.addChild( this._debugNode ); this.scheduleUpdate(); this.addBody(240,10,480,20,false,"assets/ground.png","ground"); this.addBody(204,32,24,24,true,"assets/brick1x1.png","destroyable"); this.addBody(276,32,24,24,true,"assets/brick1x1.png","destroyable"); this.addBody(240,56,96,24,true,"assets/brick4x1.png","destroyable"); this.addBody(240...