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