DrawableImage hitTest :)


#1

In working on a small app which simply abuses drawables, I discovered that the DrawableImage source has a little note in it as follows:

//xxx should use image alpha channel for hit-test?

When I typed “Yes” at the end of the line and recompiled, it didn’t change anything. :lol:

So, I figured I’d put in a special request for it here. Pretty please with C&H pure cane sugar on it, Jules, could you please implement alpha channel hit testing in drawable images?


#2

Sure, I think it’d be as simple as:

return image != 0 && x >= 0.0f && y >= 0.0f && x < image->getWidth() && y < image->getHeight() && image->getPixelAt (roundFloatToInt (x), roundFloatToInt (y)).getAlpha() >= 127;

That’s assuming an alpha threshold of 0.5, though it might be worth adding a hit test threshold setting for the drawable object.


#3

A thousand thanks again Jules. I never even considered an alpha threshold for the hit test. That is an excellent idea, as it would allow for shadows and blurred regions to not be returned in the hit test. As it stand, this will be quite sufficient for my purposes. Works perfect.


#4