Another quick one. Added some touch interaction so that the tiles can be tapped and go from a hidden to a visible.
SKNodes
can’t be tapped whilst they are hidden
(or have an alpha
of 0). In order to detect them, I’m checking the location of the touch even on the parent node and checking to see if it’s within the bounds of any of the tiles. If it is, I’m currently just marking them as visible.
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
guard let location = touches.first?.location(in: tileNode) else { return }
for case let node as SKShapeNode in tileNode.children {
if node.contains(location) && node.isHidden {
node.isHidden = false
break
}
}
}