I am building a SpriteKit game. The game scene is the parent of a transparent layer above it whose role is to display occasional messages to the player. I want this layer to be transparent and inert most of the time, and of course, never receive touches. As such, I have isUserInteractionEnabled set to false. However, when I add this later to the scene, it blocks all touches below it. What gives?
Edit: the parent of the MessageLayer is the game scene, and the game scene also has isUserInteractionEnabled = false, so I do not believe that the MessageLayer is inheriting the behavior.
Here is my code:
import Foundation
import SpriteKit
class MessageLayer: SKSpriteNode {
init() {
let size = CGSize(width: screenWidth, height: screenHeight)
super.init(texture: nil, color: UIColor.blue, size: size)
self.isUserInteractionEnabled = false
self.name = "MessageLayer"
alpha = 0.6
zPosition = +200
}
override init(texture: SKTexture!, color: UIColor, size: CGSize)
{
super.init(texture: texture, color: color, size: size)
}
required init(coder aDecoder: NSCoder) {
super.init(texture: nil, color: UIColor.clear, size: CGSize(width: 100, height: 100))
}
// MARK: - Functions
func alphaUp() {
alpha = 0.6
}
func alphaDown() {
alpha = 0.0
}
}
Just relay the touches to the scene / other nodes you want to do stuff with.
And here you can see that the invisible node is sending events properly: