【发布时间】:2015-04-16 05:54:04
【问题描述】:
您好,我很难找到适用于我的精灵的正确代码,以便仅在录制时允许小跳,而当手指在屏幕上停留时间更长时允许跳高。 (请在下面找到当前代码)
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 和 touchesEnded 只是回调事件,它们本身不会给你任何关于触摸的信息时机...
-
尝试这个问题作为开始(它是 ObjC,但应该可以翻译)stackoverflow.com/questions/1305597/…
标签: swift sprite-kit game-physics