Swift sprite kit 游戏:检测触摸并为屏幕的不同部分执行单独的代码?

Swift sprite kit game: detect touch and execute separate code for different parts of screen?

本质上,我需要知道如果用户触摸了屏幕左侧,则执行此代码,但如果他们触摸了屏幕右侧,则执行此代码。

事实上,我有在屏幕的任何地方被点击时执行的代码,因为我有它:

override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
        /* Called when a touch begins */

        for touch: AnyObject in touches {

            let location = touch.locationInNode(self)
}
}

但我需要知道如何使水龙头的位置更具体,即右侧或左侧。有没有办法通过更改代码来做到这一点,还是我必须使用按钮?我该怎么做?

你可以这样写条件

let location = touch.locationInNode(self)
if location.x < self.size.width/2 {
    // left code
}
else {
   // right code
}