I want to know how to make a player jump only once till he hits the ground, just like in the most games. I tried this: swift - Jump only when landed, but it didn't really work for me because for whatever reason the player only jumped when I spammed tapping the screen and he only jumped like every 30 click. Here is how it looks like:
That's under the: class GameScene: SkScene {
var ableToJump = true
var Player = SKSpriteNode(imageNamed: "Spieler_rechts")
In the: didMoveToView(view: SKView)
Player.position = CGPoint(x: self.frame.size.width*0.1, y: Ground.frame.size.height + Player.frame.size.height)
Player.zPosition = 3
Player.physicsBody = SKPhysicsBody(rectangleOfSize: Player.size)
Player.physicsBody?.allowsRotation = false
Player.physicsBody?.affectedByGravity = true
Player.physicsBody?.restitution = 0
self.addChild(Player)
In the: override func update(currentTime: NSTimeInterval)
if Player.physicsBody?.velocity.dy == 0 {
ableToJump = true
}
else {
ableToJump = false
}
In the: override func touchesBegan(touches: Set, withEvent event: UIEvent?)
if ableToJump == true {
Player.physicsBody?.applyImpulse(CGVectorMake(0, 20))
}