Ignore touching transparent pixels
I have a scene with many overlapping images. The images themselves can be varied. But for this example, we can say that all images are Tetris figures.
I was under the impression that when you touched a node in UItouch using spritekit, the touch would only register if you touched the opaque part of the image. However ... I quickly found that touching anywhere inside the square node registered the touch.
My solution to the problem was to assign each node to the depth z and then grab the name of what node was on top. Yes, I know ... very stupid. I am getting a list of all affected nodes, but I still have a problem where I cannot touch a node behind another node, even if it is covered with transparent space.
My next attempt was to create an SKShapeNode for each node that only masked the sections of the image where I want to detect touch. But it seems that touching the transparent area outside the form is still registering as a touch.
I was told by a developer in the Apple forums to use locationInNode (spriteNode) in UITouch. Apparently I can use the location information to find the color of the pixel I am touching in a node (to see if it is transparent or not), however there was no code related to how to get the texture color / alpha of the nodes.
Does anyone have a solution to this problem? If the screen was filled with tetrises that looked like pieces, and you tried to grab a shape from under the "T" shape, touching under - and to the left of | how would you do it? Is there an easier way? is there some way to mask just the area you want to return to?
- This is not a UIview, I am working in a spritekit with nodes and textures.
source to share
No one has answered this question yet
Check out similar questions: