From bf9547d8040cf3aed3c55d007551fb4605046dad Mon Sep 17 00:00:00 2001 From: CypherPoet Date: Thu, 7 Mar 2019 03:01:42 -0500 Subject: [PATCH] Add CAEmitter layer for some starry misdirection. --- .../Controllers/Home/HomeViewController.swift | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/37-watchkit-game-esp-tester/ESP Tester/ESP Tester/Controllers/Home/HomeViewController.swift b/37-watchkit-game-esp-tester/ESP Tester/ESP Tester/Controllers/Home/HomeViewController.swift index fa7c79a..d66b3df 100644 --- a/37-watchkit-game-esp-tester/ESP Tester/ESP Tester/Controllers/Home/HomeViewController.swift +++ b/37-watchkit-game-esp-tester/ESP Tester/ESP Tester/Controllers/Home/HomeViewController.swift @@ -25,7 +25,7 @@ class HomeViewController: UIViewController { lazy var cardPositions = makeCardPositions() lazy var cardImages = makeCardImages() - + lazy var particleEmitter = makeParticleEmitter() // MARK: - Lifecycle @@ -71,6 +71,7 @@ class HomeViewController: UIViewController { currentCardState = .allFlat } + func removeCardsInView() { for card in cardViewControllers { card.view.removeFromSuperview() @@ -92,6 +93,8 @@ class HomeViewController: UIViewController { self?.view.backgroundColor = .blue } ) + + gradientView.layer.addSublayer(particleEmitter) } @@ -150,5 +153,32 @@ class HomeViewController: UIViewController { return image } } + + + private func makeParticleEmitter() -> CAEmitterLayer { + let emitterLayer = CAEmitterLayer() + + emitterLayer.position = CGPoint(x: view.frame.midX, y: view.frame.minY - 50) + emitterLayer.emitterShape = .line + emitterLayer.emitterSize = CGSize(width: view.frame.width, height: 1) + emitterLayer.renderMode = .additive + + let emitterCell = CAEmitterCell() + emitterCell.birthRate = 2 + emitterCell.lifetime = 5.0 + emitterCell.velocity = 100 + emitterCell.velocityRange = 50 + emitterCell.emissionLongitude = .pi + emitterCell.spinRange = 5 + emitterCell.scale = 0.5 + emitterCell.scaleRange = 0.25 + emitterCell.color = UIColor(white: 1, alpha: 0.1).cgColor + emitterCell.alphaSpeed = -0.025 + emitterCell.contents = UIImage(named: "particle")?.cgImage + + emitterLayer.emitterCells = [emitterCell] + + return emitterLayer + } }