嗨,我很难找到正确的代码来应用于我的 Sprite ,以允许仅在粘贴时进行小跳跃,而当手指在屏幕上停留较长时间时允许进行更高的跳跃。 (请在下面找到当前代码)
override func touchesBegan(touches: Set<NSObject>, withEvent event:UIEvent) {
/* Called when a touch begins */
if (gameOver == 0){
//Player Begin Jumping.
player.physicsBody?.applyImpulse(CGVectorMake(0, 200))
player.runAction(SKAction .playSoundFileNamed("sounds/Jump.caf", waitForCompletion: true))
}
}
override func touchesEnded(touches: Set<NSObject>, withEvent event: UIEvent) {
if (gameOver == 0){
//Player End Jump.
player.physicsBody?.applyImpulse(CGVectorMake(0, -120))
最佳答案
您可以使用更新
方法。在你的touchesBegan方法中,你设置一个 bool 值或类似的东西来显示你仍在屏幕上按下的update
方法。例如:
//touchesBegan
touching = true
//update-method
if touching {
player.physicsBody?.applyImpulse(CGVectorMake(0, 1))
}
//touchesEnded
touching = false
您必须更改 applyImpulse
才能满足您的需求。
关于swift - 如何根据触摸屏的时间使 Sprite 跳得更高/更小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29666375/