SpriteKit is a phenomenal 2D game engine that ships in iOS and OS X. It has brought on a sort of renaissance amongst both amateur and professional game developers.
But what about using SpriteKit for fun, (and profit π), and for things other than making games? What if we used SpriteKit to add special effects and final touches to our user interfaces?
class HeartBubblesScene : SKScene {
var emitter: SKEmitterNode?
override func didMoveToView(view: SKView) {
// make scene's size == view's size
scaleMode = .ResizeFill
backgroundColor = UIColor.whiteColor()
}
func beginBubbling() {
if let e = emitter {
e.resetSimulation()
} else {
emitter = SKEmitterNode(fileNamed: heartsFile)
let x = floor(size.width / 2.0)
let y = heartHeight
emitter!.position = CGPointMake(x, y)
emitter!.name = "heart-bubbles"
emitter!.targetNode = self
addChild(emitter!)
}
}
}
class PotentialMatchViewController: UIViewController {
@IBOutlet weak var heartBubblesView: SKView!
let heartBubblesScene = HeartBubblesScene()
override func viewDidLoad() {
super.viewDidLoad()
heartBubblesView.presentScene(heartBubblesScene)
}
@IBAction func interestedTapped(sender: UIButton) {
heartBubblesScene.beginBubbling()
}
}
Here we're adding an awesome finishing touch to this pretend dating app. When the user taps the i'm interested button, we trigger an SKEmitterNode
.