It’s time to put your skills to the test and make your own app, starting from a blank canvas. This time your challenge is to make a shooting gallery game using SpriteKit: create three rows on the screen, then have targets slide across from one side to the other. If the user taps a target, make it fade out and award them points.
How you implement this game really depends on what kind of shooting gallery games you’ve played in the past, but here are some suggestions to get you started:
Those are just suggestions – it’s your game, so do what you like!
Tip: I made a SpriteKit shooting gallery game in my book Hacking with macOS – the SpriteKit code for that project is compatible with iOS, but rather than just reading my code you might prefer to just take my assets and use them to build your own project.
As always, please try to code the challenge yourself before reading any of the hints below.
moveBy()
action. Use a sequence so that targets move across the screen smoothly, then remove themselves when they are off screen.SKLabelNode
, a secondsRemaining
integer, and a Timer
that takes 1 away from secondsRemaining
every 1 second.invalidate()
when the time runs out.nodes(at:)
to see what was tapped. If you don’t find a node named “Target” in the returned array, you could subtract points for the player missing a shot.SKLabelNode
on the screen.SAVE 50% To celebrate Black Friday, all our books and bundles are half price, so you can take your Swift knowledge further without spending big! Get the Swift Power Pack to build your iOS career faster, get the Swift Platform Pack to builds apps for macOS, watchOS, and beyond, or get the Swift Plus Pack to learn advanced design patterns, testing skills, and more.
Sponsor Hacking with Swift and reach the world's largest Swift community!
Link copied to your pasteboard.