1
我想輕掃手勢添加到節點輕掃手勢添加到節點,以便當用戶刷它,它會關閉屏幕,但我不斷收到一個錯誤SIGABRT
:如何spritekit
`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")
}
}
}
用'#selector(PlankScene.swipedRight)替換'Selector(「swipedRight:」)'' – 0x141E
驗證didMove只被調用一次,並刪除您的deinit中的手勢。 – Knight0fDragon
手勢識別器不會添加到節點,而是添加到視圖中... – Whirlwind