|
|
@@ -1,3 +1,4 @@
|
|
|
+import Foundation
|
|
|
import SpriteKit
|
|
|
|
|
|
class SnowScene: SKScene {
|
|
|
@@ -9,6 +10,22 @@ class SnowScene: SKScene {
|
|
|
snowEmitterNode.particleLifetime = 2
|
|
|
snowEmitterNode.particleLifetimeRange = 6
|
|
|
addChild(snowEmitterNode)
|
|
|
+ subscribe()
|
|
|
+ }
|
|
|
+
|
|
|
+ private func subscribe() {
|
|
|
+ Foundation.NotificationCenter.default.addObserver(
|
|
|
+ self,
|
|
|
+ selector: #selector(didEnterBackground),
|
|
|
+ name: UIApplication.didEnterBackgroundNotification,
|
|
|
+ object: nil
|
|
|
+ )
|
|
|
+ Foundation.NotificationCenter.default.addObserver(
|
|
|
+ self,
|
|
|
+ selector: #selector(willEnterForeground),
|
|
|
+ name: UIApplication.willEnterForegroundNotification,
|
|
|
+ object: nil
|
|
|
+ )
|
|
|
}
|
|
|
|
|
|
override func didChangeSize(_: CGSize) {
|
|
|
@@ -16,4 +33,12 @@ class SnowScene: SKScene {
|
|
|
snowEmitterNode.particlePosition = CGPoint(x: size.width / 2, y: size.height)
|
|
|
snowEmitterNode.particlePositionRange = CGVector(dx: size.width, dy: size.height)
|
|
|
}
|
|
|
+
|
|
|
+ @objc private func didEnterBackground() {
|
|
|
+ isPaused = true
|
|
|
+ }
|
|
|
+
|
|
|
+ @objc private func willEnterForeground() {
|
|
|
+ isPaused = false
|
|
|
+ }
|
|
|
}
|