A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: BitmapData.hitTest() how accurate?

  1. #1
    Senior Member
    Join Date
    May 2006
    Posts
    145

    BitmapData.hitTest() how accurate?

    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.

    Code:
    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
    Last edited by ArielGenesis; 09-06-2007 at 01:46 AM.

  2. #2
    Senior Member
    Join Date
    May 2006
    Posts
    145
    can someone help me with this? I have no idea where to go?

  3. #3
    Knows where you live
    Join Date
    Oct 2004
    Posts
    944
    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.
    The greatest pleasure in life is doing what people say you cannot do.
    - Walter Bagehot
    The height of cleverness is to be able to conceal it.
    - Francois de La Rochefoucauld

  4. #4
    Senior Member
    Join Date
    May 2006
    Posts
    145
    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.

  5. #5
    Senior Member joshstrike's Avatar
    Join Date
    Jan 2001
    Location
    Alhama de Granada, España
    Posts
    1,136
    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...

  6. #6
    Senior Member
    Join Date
    May 2006
    Posts
    145
    well, It was a test, so I convert it. May be ur right, let me check that again.

  7. #7
    Senior Member
    Join Date
    May 2006
    Posts
    145
    yoho
    hahhahha
    Its working
    thanksss

  8. #8
    Senior Member
    Join Date
    Jan 2008
    Posts
    150
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center