【发布时间】:2015-04-23 16:19:33
【问题描述】:
当用户触摸屏幕并按住它时,我希望SKSpriteNode 飞起来,当用户停止触摸后,它又会掉到地上。现在我正在使用敲击将节点向上移动并在 touchesEnded 中将重力设置为 false 以使其落到地上。我将如何让它发挥作用。谢谢!
var touchingScreen = false
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
super.touchesBegan(touches, withEvent: event)
touchingScreen = true
}
override func touchesCancelled(touches: Set<NSObject>!, withEvent event: UIEvent!) {
super.touchesCancelled(touches, withEvent: event)
touchingScreen = false
}
override func touchesEnded(touches: Set<NSObject>, withEvent event: UIEvent) {
super.touchesEnded(touches, withEvent: event)
touchingScreen = false
}
override func update(currentTime: CFTimeInterval) {
if touchingScreen {
// Adjust the CGVector to suit your needs.
heroNode.physicsBody!.applyImpulse(CGVector(dx: 0, dy: 10))
}
}
【问题讨论】:
标签: xcode swift touchesbegan