The elusive hitTest explained
Back by popular demand!
HitTest is a very useful, and can be used for just about anything (like ductape really). There are two main forms that it takes:
Code:
if(this.hitTest(another_clip)){
// Something
}
This just tests the bounding boxes of this, and another_clip. If they hit, then the contents of the if will run.
Code:
if(this.hitTest(x, y, true)){
// Something
}
This tests the point x,y against the contents of this, the actual shape and not the bounding box. The true is what makes it test against the shape and not the bounding box.
Anyone else want to continue?
(if it's an irrelevant post, it'll be edited out as this is a guide sticky, not just a general bantering one ;))
if you don't understand this
If you don't understand how to make solid objects (stuff that your character can't walk through) then do this: Go here: HERE . I guarantee that you won't be dissapointed. Look at the "lastish" post, there I explain it pretty well - I think.
I don't like hitTest() :)
It's one of those pointless functions in Flash that need not exist.
this is how I do collision detection:
if((_x+_width/2>_root.object2._x-_root.object2._width/2 && _x-_width/2<_root.object2._x+_root.object2._width/2) && _root.object2.dead == false){
_root.object2.dead = true
}
that way you don't have to bother with stupid things like drawing boxs for hitTest and crap.
the only thing I've seen hitTest do that impressed me was "contour collision" in other words shapeflag.
but still you don't really need that for 90% of the games you will create.