如何为spritekit中的节点添加滑动手势

How to add a swipe gesture to a node in spritekit

我正在尝试向节点添加滑动手势,以便当用户滑动它时,它会离开屏幕,但我一直收到 SIGABRT 错误:

`Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[fidget2.PlankScene swipedRight:]: unrecognized selector sent to instance 0x7ff4c3603e00'`

我不确定为什么会弹出此错误。我确保节点在 .sks 文件中被正确标记。这是我的代码:

import SpriteKit


let plankName = "woodPlank"

class PlankScene: SKScene {

  var plankWood : SKSpriteNode?


  override func didMove(to view: SKView) {

    plankWood = childNode(withName: "woodPlank") as? SKSpriteNode


    let swipeRight : UISwipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: Selector("swipedRight:"))

    swipeRight.direction = .right

    view.addGestureRecognizer(swipeRight)

  }


  func swipedRight(sender: UISwipeGestureRecognizer) {

    print("Object has been swiped")

  }


 func touchesMoved(touches: Set<NSObject>, withEvent event: UIEvent)
  {
    let touch = touches.first as! UITouch
    let location = touch.location(in: self)

    if (plankWood?.frame.contains(location))!
    {
     print("Swipe has started")
    }
  }
}

有同样的问题,所以我们对此有一个可接受的答案我想指出 0x141E 留下的评论是正确的解决方案:

Selector("swipedRight:")替换为#selector(PlankScene.swipedRight)