;

PDA

Click to See Complete Forum and Search --> : BitmapData.hitTest() how accurate?


ArielGenesis
09-06-2007, 01:42 AM
I am using BitmapData.hitTest() and want to know why it is not accurate.
and the next question will be, how to make it accurate.

public static function pixelHitTest(mc1:MovieClip,mc2:MovieClip):Boolean {
var mc1bd:BitmapData = new BitmapData(mc1.width, mc1.height, true, 0);
mc1bd.draw(mc1);
var mc2bd:BitmapData = new BitmapData(mc2.width, mc2.height, true, 0);
mc2bd.draw(mc2);
if (mc1bd.hitTest(new Point(mc1.x, mc1.y), 0xFF, mc2bd, new Point(mc2.x, mc2.y))) {
return true;
} else {
return false;
}
}


here is the link to show that it is not accurate.
http://www.geocities.com/arian_m3/bitmaphittest.swf

thank you in advance

ArielGenesis
09-07-2007, 09:00 PM
can someone help me with this? I have no idea where to go?

691175002
09-07-2007, 10:36 PM
I am almost positive that it is accurate, you are just using it improperly. I have never used bitmap hittests, but I know there are lots of tutorials on them which are extremely accurate.

ArielGenesis
09-07-2007, 10:51 PM
I know, I took the function from somewhere else? is there is some special cases? like i have to do something or I should not do something. I also copy paste and tweak the code from FFiles. Thank you. But I am still confused.

joshstrike
09-08-2007, 12:29 PM
Well...first of all, I don't see a reason to convert these to bitmapdata...secondly, look at where the point you're testing is... it's at x:0 y:0 on mc1. So if mc1 has no actual pixels at its origin point, the test will return false...

ArielGenesis
09-11-2007, 05:47 AM
well, It was a test, so I convert it. May be ur right, let me check that again.

ArielGenesis
09-11-2007, 06:15 AM
yoho
hahhahha
Its working
thanksss

Shokushu
01-07-2008, 01:31 PM
I was having some weird false positives in a program I was doing awhile back-

I had a big "+" shaped object and a smaller character- knowing about bounding boxes I broke the "+" into squares the size of the character but the hit tests would sometimes return positive where they obviously were not.


I eventually ended up using this complicated class someone else gave me for pixel precise hit tests to get around it.