- Hello, so I've been recently using
hitTestObject
to detect collisions in an android app I'm making. After testing for a bit, I realized that the game was detecting "fake" collisions. What I mean by this is that it was detecting a collisions not when the pixels of an object(s) are touching, but (after doing a bit of research) I found out that the boxes of the objects where colliding. So I had the game stop with a collision, and this is how it looks like:
I tried outlining the two object's boxes, for clarity. As you can see their boxes are touching. Is there any way to have it detect when pixels collide?
- I assume there would be something online for this, but I do not know what. The game is programmed through the actions window, not a class files, so there is no package, nor class, and any collision detection "function" online, that need a class to work, probably won't work here.
Anyway: is there any way in actionscript-3 to detect pixels colliding, and if so. What function and/or command could I use for that?
As you correctly notice, hit areas in hitTestObject are by default rectangular, as they use the bounding box.
You can test against the object's actual shape on a point-by-point basis using...
(See the documentation.)
For custom-shaped hit areas, you can also use bitmap hit testing. (See accepted answer here.)
you can do it this way
if(instanceName1.hitTestObject(instancename2) == true) { //execute the code you want }
instanceName1 and 2 are the given name in the porgramCollision detection has been a major hurdle for coders for years. There are many different methods for detecting collisions:
I found hitTestPoint to be the most practical. However, in your case you may want to go along the lines of BitmapData: http://www.freeactionscript.com/2011/08/as3-pixel-perfect-collision-detection/
Cheers, Drake Swartzy