我正在用 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
}