Catch The Light – Free with In-App Purchases – Achievements and Leaderboards.

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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//Setting up the light's sprite.
var lightOff1 = SKSpriteNode(imageNamed: "light_off_black_001")

//Setting the speed of the light.
var speedOfLights = 1.0

//Configuring the lights position, name, and adding in to the scene.
lightOff1.position = CGPoint(x:CGRectGetMidX(self.frame), y:CGRectGetMidY(self.frame))
lightOff1.name = "lightOff1"
self.addChild(lightOff1)

//Some actions to emulate flashing.
var wait = SKAction.waitForDuration(speedOfLights)
var wait1 = SKAction.repeatAction(wait, count: 1)
var turnLightOn = SKAction.setTexture(SKTexture(imageNamed: "light_on_001"))
var turnLightOff = SKAction.setTexture(SKTexture(imageNamed: "light_off_black_001"))
var lightSound = SKAction.playSoundFileNamed("short_bell.wav", waitForCompletion: false)
var lightingSequence1 = SKAction.sequence([lightSound, turnLightOn, wait, turnLightOff, wait1])

//And finally running the action.
lightOff1.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. Below, I have preview video for Catch The Light so you can see the effect in action: