我在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