/ Published in: ActionScript 3
A fast and accurate Hit Test that can check if objects truly touch each other.
This differs from HitTestObject, as it actually checks if objects visually hit, rather then their boundary boxes. Include this function in your code, for easy, efficient and effortless collision detection!
This differs from HitTestObject, as it actually checks if objects visually hit, rather then their boundary boxes. Include this function in your code, for easy, efficient and effortless collision detection!
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/* Created by Sam Kantor Example Usage: if (ObjectsHit(myobject, myotherobject)) { The Objects hit! } */ function ObjectsHit(mc1, mc2):Boolean { var mc1bounds = mc1.getBounds(this); var mc2bounds = mc2.getBounds(this); var allintersections = (mc2bounds.intersection(mc1bounds)); for (var xval:Number = allintersections.x; xval < allintersections.x + allintersections.width; xval ++ ) { for (var yval:Number = allintersections.y; yval < allintersections.y + allintersections.height;yval ++ ) { if (mc2.hitTestPoint(xval, yval, true) && mc1.hitTestPoint(xval, yval, true)) { return(true); } } } return(false);