Search code examples
iossprite-kittouch-eventskspritenodeskshapenode

Touch through a node in SpriteKit


So I am working on making a tower defense game and have the tile board working and able to place towers... to a degree.

When a player clicks a button above the grid, it will toggle on the tower placement and allow the player to place towers on a cell within the grid. However, each tower is also getting a circle ShapeNode around it to handle detection of a creep moving into firing range. This shape node shows up just fine around the tower once I place them.

The logic I used to place the towers is that it finds the node you touch (named "cell") and replaces it with a tower node. But if the tower node has the circle node attached and covering a cell next to it, I am unable to select the cell node below the circle.

How would I go about touching "through" the circle, or setting its fill space to be nothing so that I can access the cells below it?

I'm still learning sprite-kit as I go, so if there may be a simpler approach feel free to point me in the right direction too.


Solution

  • Without seeing any of your relevant code it's hard to say for certain but from your description, I think your issue is with the shape node. Instead of using a shape node to handle your contacts, I would suggest you use the tower's physics body instead. You can still have a circular physics body for your towers without resorting to adding a whole new node. Removing the shape node will also resolve your cross touch interference.