我正在构建一个 SpriteKit 游戏。游戏场景是其上方透明层的父级,其作用是向玩家显示偶尔的消息。我希望这个层在大多数情况下都是透明的和惰性的,当然,永远不要被触摸。因此,我将 isUserInteractionEnabled 设置为 false。但是,当我稍后将其添加到场景中时,它会阻止其下方的所有触摸。是什么赋予了?
编辑:MessageLayer 的父级是游戏场景,游戏场景也有 isUserInteractionEnabled = false,所以我不相信 MessageLayer 是在继承行为。
这是我的代码:
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
}
}