如何处理 SKShapeNode 子类中的触摸?

use*_*007 2 touchesbegan ios sprite-kit skshapenode swift

我正在寻找一种简单的方法来处理 SKShapeNode 子类中的触摸。为此,我尝试使用touchesBegan,但它不起作用..

class Shape: SKShapeNode {


convenience init(rectOfSize: CGSize, colorOfRectangle rectColor: UIColor) {

    self.init()

    self.init(rectOfSize: rectOfSize)
    self.fillColor = rectColor
    self.position = CGPointMake(rectOfSize.width, rectOfSize.height)
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
    print("touch")   
}
}
Run Code Online (Sandbox Code Playgroud)

And*_*kha 5

确保userInteractionEnabled将形状对象设置为true。它是false默认的