I have been struck with the famous "unrecognized selector sent to instance". The full error is
-[MyGame.GameScene handlePanFrom:]: unrecognized selector sent to instance 0x103c05fe0
The function that is referring to is her in the game scene:
func handlePanFrom(recognizer: UIPanGestureRecognizer) {
if recognizer.state == .began {
var touchLocation = recognizer.location(in: recognizer.view)
touchLocation = self.convertPoint(fromView: touchLocation)
self.selectNodeForTouch(touchLocation: touchLocation)
} else if recognizer.state == .changed {
var translation = recognizer.translation(in: recognizer.view!)
translation = CGPoint(x: translation.x, y: -translation.y)
self.panForTranslation(translation: translation)
recognizer.setTranslation(CGPoint.zero, in: recognizer.view)
} else if recognizer.state == .ended {
if selectedPlayer.name != kAnimalNodeName {
let scrollDuration = 0.2
let velocity = recognizer.velocity(in: recognizer.view)
let pos = selectedPlayer.position
// This just multiplies your velocity with the scroll duration.
let p = CGPoint(x: velocity.x * CGFloat(scrollDuration), y: velocity.y * CGFloat(scrollDuration))
var newPos = CGPoint(x: pos.x + p.x, y: pos.y + p.y)
newPos = self.boundLayerPos(aNewPosition: newPos)
selectedPlayer.removeAllActions()
let moveTo = SKAction.move(to: newPos, duration: scrollDuration)
moveTo.timingMode = .easeOut
selectedPlayer.run(moveTo)
}
}
}
And then this code in the game scene did move function
let gestureRecognizer = UIPanGestureRecognizer(target: self, action: Selector(("handlePanFrom:")))
self.view!.addGestureRecognizer(gestureRecognizer)
If you need to see any of the other code I will provide.
It should also be noted that I changed some code in the GameViewController but I don't know if that has anything to do with it.