I'm writing a game for Mac using Cocoa. I'm currently implementing hit testing and have founds that CALayer offers hit testing, but does not seem to implement the alpha properties. As I have at times many CALayers stacked on top of each other, I really need to find a way to determine what the user actually meant to click on.
I'm thinking if I could somehow get an array that contains pointers to all of the CALayers that contain the click point, I could filter through them some how. However the only way I've got so far to create the array is:
NSMutableArray* anArrayOfLayers = [NSMutableArray array];
for (CALayer* aLayer in mapLayer.sublayers)
{
if ([aLayer containsPoint:mouseCoord])
[anArrayOfLayers addObject:aLayer];
}
Then sort the array by the CALayer's z-values then go through checking if the pixel at location is alpha or not. However, between the sort and the alpha check this seems to be an incredible performance hog. (How would you even check the alpha?)
Is there any way to do this?