Catch The Light - A classic arcade game for your iPhone
Catch The Light - Free with In-App Purchases - Supports Achievements and Leaderboards.
The game
Catch The Light is a special project for me considering its inspiration was a favorite arcade game of mine growing up. In Catch The Light, you must stop the light on one of the four green bulbs on the screen. Each time you score - the game gets faster.
Written entirely in Swift, Catch The Light makes heavy use of SKActions's within SpriteKit in order to present its flashing lights. As usual, when I release an application, I like to take the opportunity to explain some of the techniques I used.
In order to imitate the flashing you see in Catch The Light, first you must place your turned off light image on the screen. Then, whenever you start the game, have your light run an SKAction that waits, plays a sound, turns on the light, and turns off the light. For the light to turn on and off, we replace the initial sprite's textures quickly in succession. It should look something like this:
Code example
1// Setting up the light's sprite. 2var lightOff1 = SKSpriteNode(imageNamed: "light_off_black_001") 3 4// Setting the speed of the light. 5var speedOfLights = 1.0 6 7// Configuring the lights position, name, and adding in to the scene. 8lightOff1.position = CGPoint(x:CGRectGetMidX(self.frame), y:CGRectGetMidY(self.frame)) 9lightOff1.name = "lightOff1" 10self.addChild(lightOff1) 11 12// Some actions to emulate flashing. 13var wait = SKAction.waitForDuration(speedOfLights) 14var wait1 = SKAction.repeatAction(wait, count: 1) 15var turnLightOn = SKAction.setTexture(SKTexture(imageNamed: "light_on_001")) 16var turnLightOff = SKAction.setTexture(SKTexture(imageNamed: "light_off_black_001")) 17var lightSound = SKAction.playSoundFileNamed("short_bell.wav", waitForCompletion: false) 18var lightingSequence1 = SKAction.sequence([lightSound, turnLightOn, wait, turnLightOff, wait1]) 19 20// And finally running the action. 21lightOff1.runAction(SKAction.repeatActionForever(lightingSequence1))
Create more light sprites and assign them new actions to get the effect going.
As you can see, Apple's SpriteKit is a snap to use and lets you quickly assign actions and animation to any sprite you'd like. Here's a preview video for Catch The Light so you can see the effect in action.