我在Swift和SpriteKit中創建了一個Side Scroller類似馬里奧的遊戲。我目前正在移動播放器,但你必須保持點擊,然後移動。我所希望的是,如果你堅持它,它會移動,你不必快速點擊屏幕。先謝謝你 !!!!連續觸摸/移動Swift和SpriteKit
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
for touch: AnyObject in touches {
let location = touch.locationInNode(self)
if location.y > 400{
move = true
}else{
if location.x < CGRectGetMidX(self.frame){
player.physicsBody?.applyImpulse(CGVector(dx: -30, dy: 0))
//tap somewhere above this to make character jump
if(location.y > 250) {
player.physicsBody?.applyImpulse(CGVector(dx: 0, dy: 200))
}
} else if location.x > CGRectGetMidX(self.frame){
player.physicsBody?.applyImpulse(CGVector(dx: 30, dy: 0))
//tap somewhere above this to make character jump
}
}
}
}
override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
move = false
}
看起來像設置一次移動,只移動一次你的對象?只要用戶沒有舉起手指,你想不斷調用它嗎? – Shripada
是的像在JavaScript中有一個名爲** mouseIsPressed **的布爾值,這基本上是我需要的。 – ScarletStreak