3

I have a scene with many overlapping images. The images themselves can be a variety of shapes. But for this example lets say all the images are tetris shapes.

I was under the impression that when you touched on a node in UItouch using spritekit that the touch would only register if you touched on a non-transparent section of the image. However... I quickly discovered that touching anywhere inside the square node registered a touch.

My solution to the problem was to assign every node a z depth and then grab the name of whatever node was on top. Yes, I know... very stupid. I get a list of all the nodes touched, but I still have the problem where I can't touch a node behind another node even if it's covered with transparent space.

My next attempt was to create an SKShapeNode for each node that masked just the sections of the image I want to detect a touch on. But it seems touching a transparent area outside the shape still registers as a touch.

I was told by a dev on the Apple forums to use locationInNode(spriteNode) on the UITouch. Apparently I can use the location information to look up the pixel color I'm touching in the node (to see if it's transparent or not), however there was no code attached on how to get the color / alpha of the nodes texture.

Does anyone have a solution to this problem? If the screen was filled with tetris like pieces and you were trying to grab a shape from underneath a 'T' shaped piece by touching under the - and to the left of the | how would you do this? Is there an easier way? is there some way to mask off just the area you want to return touches on?

  • This is not a UIview, I'm working in spritekit with nodes and textures.
NeHe
  • 31
  • 2

0 Answers0