2016-09-30 52 views
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") 
    } 
    } 
} 
+1

用'#selector(PlankScene.swipedRight)替換'Selector(「swipedRight:」)'' – 0x141E

+0

驗證didMove只被調用一次,並刪除您的deinit中的手勢。 – Knight0fDragon

+0

手勢識別器不會添加到節點,而是添加到視圖中... – Whirlwind

回答

3

有同樣的問題,只是讓我們有這樣的一個公認的答案,我想指出的是,通過0x141E留下的評論是正確的解決方案,這一點:

更換Selector("swipedRight:")#selector(PlankScene.swipedRight)