I have an SKSpriteNode called runner and whenever I touch the screen to try to drag it from one place to another, runner goes the opposite way? For example, if I try to drag it left, it goes right, if I try to drag it up then it goes down. Adding TouchesEnded did not help. Can anyone look at my code and tell me why this is happening please?
import UIKit
import Foundation
import SpriteKit
class Maze: SKScene {
let runner = SKSpriteNode(imageNamed: "Spaceship")
override func didMoveToView(view: SKView)
{
self.createRunner()
}
override func touchesBegan(touches: NSSet, withEvent event: UIEvent)
{
let touch = touches.anyObject()! as UITouch
let location = touch.locationInView(self.view)
runner.position = location
}
override func touchesMoved(touches: NSSet, withEvent event: UIEvent)
{
let touch = touches.anyObject()! as UITouch
let location = touch.locationInView(self.view)
runner.position = location
}
func createRunner()
{
runner.setScale(0.50)
runner.position = CGPointMake(0, 0)
runner.name = "RunnerNode"
self.addChild(runner)
}
}
This code is working fine: