I have an SKSpriteNode that has a texture assigned like this:
node.texture = SKTexture(imageNamed: "Oval")
Users can select this object and drag it around. I use the following to identify when it is being selected in the touchesMoved function.
var touchedNode = allObjects.nodeAtPoint(location)
The problem is that almost half the surface area of this image file is transparent. However, nodeAtPoint responds to touches on the transparency.
Does anyone know of a way to ignore the transparency?
In your touches Moved you can get the color of the pixel of the node you touched and then using an if statement you can ignore the node if the color is transparent (has an alpha of 0). Check here to see how to get the color
SpriteKit: How can I get the pixel color from a point in SKSpriteNode?
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