Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Efficient irregular bitmap hit area

I have a Flash project that must display a large amount of irregularly shaped bitmaps (around 10000) and I want to know what bitmap the mouse is currently over. If the mouse is over a transparent part of the bitmap, it shouldn't count as mouse over.

One way to do this is to calculate the hit area, then replace each bitmap with a Sprite containing the bitmap and another Sprite with the calculated hit area, then set the hitArea property. But this is highly inefficient and the result is completely unusable.

What's the most efficient way to do this?

like image 506
rid Avatar asked Mar 20 '26 10:03

rid


2 Answers

Try this on the container:

var hits:Array = getObjectsUnderPoint(new Point(mouseX, mouseY));
if(hits.length > 0)
{
    var bitmap:Bitmap = hits[0] as Bitmap;
    var color:uint = bitmap.bitmapData.getPixel32(bitmap.mouseX, bitmap.mouseY);
    if(color >>> 24 > 0)
    {
        trace('hit: '+bitmap);
    }
}

If the Bitmaps overlap, iterate over hits. You can also set a threshold for the transparency.

like image 177
Sean Fujiwara Avatar answered Mar 22 '26 05:03

Sean Fujiwara


Check this transparent PNG example out, I think it may be just what you're looking for.

Here is a link to the demo.

Best of luck.

like image 29
Jacksonkr Avatar answered Mar 22 '26 04:03

Jacksonkr