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?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With