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


SpriteKit - controlling how quickly the player can shoot

I feel like the biggest problem with a game like space cat is that the player can just tap with all of their fingers as fast as they want and they will never lose the game.

Has anyone tried to tackle this problem? Perhaps by having a bar that drains as you tap quickly. If it runs out you cant shoot anymore. it could replenish itself by one unit every .5 second or something.

a more simple solution might be to limit the number of projectiles that can be on the screen to 4 or 5? Or possibly even limiting the game so that it will only respond to one tap at a time?

I see that Udemy has a section on this exact problem in their complete ios game course, but obviously I don't want to pay $499 for one little bit of code haha.

Any ideas? Thanks!

2 Answers

Stone Preston
Stone Preston
42,016 Points

maybe use NSTimer to time 1 or 2 second intervals. when the player taps to shoot start the timer and set a flag (ie lockShooting = true) and when the time expires set the flag back to false. in your projectile method you would check to see if this flag was set and if lock shooting is true then dont fire, if its false fire away

Thanks Stone, That works pretty well!