我正在寻找一种简单的方法来处理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")
}
}
答案 0 :(得分:2)
确保形状对象的userInteractionEnabled
设置为true
。默认情况下为false