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

时间:2016-03-14 19:58:22

标签: ios swift sprite-kit touchesbegan skshapenode

我正在寻找一种简单的方法来处理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")   
}
}

1 个答案:

答案 0 :(得分:2)

确保形状对象的userInteractionEnabled设置为true。默认情况下为false