override func touchesMoved(touches: NSSet, withEvent event: UIEvent) {
for touch: AnyObject in touches {
let location = touch.locationInNode(self)
let previousLocation = touch.previousLocationInNode(self)
var translation = CGPointMake(location.x - previousLocation.x, location.y - previousLocation.y)
crossHair.position = CGPointMake(crossHair.position.x + translation.x * 3, crossHair.position.y + translation.y * 3)
}
}
我在屏幕上有一個十字準線,我可以使用touchesmoved如上所示移動它,但是我的問題是我不知道如何防止它進入屏幕。有fmaxf
& fminf
但我不完全確定如何使用它們,任何幫助將不勝感激。鉗位節點到屏幕邊界
謝謝你,完美的作品。 – Abdou023 2015-03-02 13:44:22