touchesBegan на SKShapeNode не получает имя узла - PullRequest
0 голосов
/ 17 января 2019

Я расширяю класс SKShapeNode и хочу реализовать метод touchesBegan, который должен возвращать имя затронутого узла. Создано несколько экземпляров этого класса.

Однако имя узла не печатается, оно всегда печатается (ноль).

var menu: ResourceMenu

init(screenSize: CGSize, rectOf: CGSize, cornerRadius: CGFloat, color: UIColor, position: CGPoint, resource: String) {
    self.menu = ResourceMenu(_size: screenSize)

    super.init()

    let rect = CGRect(x: -rectOf.width / 2, y: -rectOf.height / 2, width: rectOf.width, height: rectOf.height)
    self.path = CGPath(roundedRect: rect, cornerWidth: CGFloat(10), cornerHeight: CGFloat(10), transform: nil)

    self.position = CGPoint(x: position.x, y: position.y)
    self.fillColor = color
    self.strokeColor = color
    self.zPosition = 10
    self.isUserInteractionEnabled = true
    self.name = resource

    menu.addChildNodes()
    menu.position = CGPoint(x: -position.x, y: -position.y)

    self.addChild(menu)
}

required init?(coder aDecoder: NSCoder) {
    fatalError("init(coder:) has not been implemented")
}

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
    let touch = touches.first!
    let location = touch.location(in: self)
    let node: SKNode = self.atPoint(location)

    print(node.name)
}
...