-
Notifications
You must be signed in to change notification settings - Fork 1
/
EndlessParallaxBackgroundCamera.swift
50 lines (40 loc) · 1.29 KB
/
EndlessParallaxBackgroundCamera.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
//
// EndlessParallaxBackground.swift
//
// Created by gitmalong
// SKCameraNode Subclass that controls CameraNodeParallax and EndlessBackgroundNode
//
import Foundation
import SpriteKit
class EndlessParallaxBackgroundCamera:SKCameraNode {
var endlessBackgrounds:[EndlessBackground] = [EndlessBackground]()
var parallaxBackgrounds:[ParallaxBackgroundMover] = [ParallaxBackgroundMover]()
init(position:CGPoint) {
super.init()
self.position = position
self.name = "camera"
}
func addEndlessBackground(ebg:EndlessBackground) {
endlessBackgrounds.append(ebg)
}
func addParallaxBackground(pbg:ParallaxBackgroundMover) {
parallaxBackgrounds.append(pbg)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override var position : CGPoint {
didSet {
if endlessBackgrounds.isEmpty == false {
for ebg in endlessBackgrounds {
ebg.triggerDraw()
}
}
if parallaxBackgrounds.isEmpty == false {
for pbg in parallaxBackgrounds {
pbg.triggerChange(position,oldCameraPosition: oldValue)
}
}
}
}
}