我有一個按鈕,當按下將移動一個節點。如何在按下按鈕時重複這個不停的操作。我想我正在尋找touchesBegan和touchesEnded之間的東西。有點像touchesContinue,因爲我希望節點在按下按鈕時繼續移動。這是我迄今爲止所擁有的。有什麼會重複touchesBegan?
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
// 1
leftMove.name = "Left"
rightMove.name = "Right"
/* Called when a touch begins */
for touch: AnyObject in touches {
let location = touch.locationInNode(self)
let node = self.nodeAtPoint(location)
if (node.name == "Left") {
// Implement your logic for left button touch here:
player.position == CGPoint(x:player.position.x-1, y:player.position.y)
} else if (node.name == "Right") {
// Implement your logic for right button touch here:
player.position = CGPoint(x:player.position.x+1, y:player.position.y)
}
}
查找'NSTimer'。在touchesBegan:withEvent:中打開它,並在touchesEnded:withEvent:中將其關閉。 –