【问题标题】:How to handle touches in SKShapeNode subclass?如何处理 SKShapeNode 子类中的触摸?
【发布时间】:2016-03-14 19:58:21
【问题描述】:

我正在寻找一种在 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")   
}
}

【问题讨论】:

    标签: ios swift sprite-kit touchesbegan skshapenode


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多