Detect touches inside the texture of an irregularly shaped Sprite

What is a good technique to detect touches within the texture of a sprite that is not a rectangle? Setting userInteractionEnabled to true enables touches on the bounding box of the sprite, but I only want touches to register when they fall inside the texture of the sprite, I don’t want them to register if the alpha is 0. I thought using physics bodies to approximate the sprite shape would work, but it still leaves the problem of how to detect touches only within the physics body boundaries.

I think you need a contactTestBitMask - you can read all about it in this tutorial.

If you’re not using SpriteKit then things get a little bit harder! You would need to keep a reference to the raw bits of your sprite image and on receiving a touch within the sprite’s bounding box, you would check the alpha value of the pixel at that point, discarding it if alpha was less than about 0.05.

Thank you! I’ll try that!