Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

How to double jump on game using sprite kit in Swift?

I'm very new to coding and I'm doing this game in swift but I'm stuck because my character jumps infinitely when I tap nonstop the screen.

I would like to make the character jump only twice, like a double jump and no more.

How can I write this code? Please!

Heres my code:

     dude.physicsBody = SKPhysicsBody(circleOfRadius: dude.size.height / 2)
    dude.physicsBody?.dynamic = true
    dude.physicsBody?.allowsRotation = false

 }

}

override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {

dude.physicsBody?.velocity = CGVectorMake(0, 0)
dude.physicsBody?.applyImpulse(CGVectorMake(0, 200))

}

override func update(currentTime: CFTimeInterval) {

}

1 Answer

Really? I never ask anything and a simple question like that that's nobody who could help me? This makes me wonder why i keep my subscription. Thanks team tree house.