Make player double jump Sprite Kit Swift

Viewed 305

I have implemented a single jump for my player. But I want the player to be able to double jump if the user taps twice.

How do I make this function below check to see if the jump is still in duration, so that they can tap and jump again if they want?

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {

    var isJumping = false
    var isDoubleJumping = false

    if mario.action(forKey: "jump") == nil && isJumping {

        let marioTextureJump = SKTexture(imageNamed: "mariojump.png")

        let animation = SKAction.animate(with: [marioTextureJump], timePerFrame: 0.6)

        mario.run(animation)

        mario.run(jumpAction, withKey: "jump")

        if isJumping {

            isDoubleJumping = true
            isJumping = false
        }

        else {

            isJumping = true
            isDoubleJumping = false
        }
    }
}
1 Answers
Related