A simple description of the game's collision detection principle: First to specify a collision detection area for each game object, and then in the Update method in real-time detection of two objects in the region whether there is overlap, if there is, then a collision occurs.
Simply look at the code, which is extracted from the official code.
1Tools. Collisionhelper={2Iscollided:function(CCA,CCB) {3 varAx = cca.x, ay = cca.y, bx = ccb.x, by =ccb.y;4 /*if (Math.Abs (AX-BX) > 5| | Math.Abs (ay-by) >5) {5 return false;6 }*/7 varArect = This. Makecolliderect (CcA);8 varBrect = This. Makecolliderect (CcB);9 returnCc.rectintersectsrect (Arect, brect);Ten }, OneMakecolliderect:function(CcA) { A returnCc.rect (cca.x-3, cca.y-3, 20, 20); - } -};
Simply say the code: Collision detection is compared to each game object in the collision area (the above code we set the area aspect is 20, the area coordinates is the current game object coordinates minus 3, this 3 must be based on different objects in the game to dynamically adjust), to get the two areas where the location, Send the Cc.rectinterestsrect function to it. In fact within the Cc.rectinterestsrect function is also done in the area range detection.
If you want to hide the game object after a collision, use it directly: Gameobject.setvisibility (false).
Words with collision detection results with Cc.fadein and cc.fadeout can be very simple to make a collision animation out.
"COCOS2D-X-JS Series" Collision detection