add button to SettingsScene for Background Movement
This commit is contained in:
parent
40890f4e37
commit
284cf1381b
@ -12,6 +12,7 @@ class BackgroundComponent: GKComponent{
|
||||
|
||||
var nodes = [SKSpriteNode]()
|
||||
let size: CGSize
|
||||
static var isMovingBackgroundEnabled: Bool = true
|
||||
|
||||
init(size: CGSize) {
|
||||
self.size = size
|
||||
@ -27,6 +28,7 @@ class BackgroundComponent: GKComponent{
|
||||
}
|
||||
|
||||
func update(){
|
||||
if BackgroundComponent.isMovingBackgroundEnabled == true {
|
||||
for node in nodes{
|
||||
node.position.x -= 2
|
||||
if node.position.x < -(size.width) {
|
||||
@ -34,6 +36,7 @@ class BackgroundComponent: GKComponent{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
fatalError("init(coder:) has not been implemented")
|
||||
|
@ -36,6 +36,19 @@ class SettingsScene: SKScene {
|
||||
SoundManager.startMenuMusic()
|
||||
}
|
||||
|
||||
}))
|
||||
entityManager.add(Button(name: "StopMovingBackground",
|
||||
iconName: "",
|
||||
text: "MOVE/STOP",
|
||||
position: CGPoint(x: self.size.width / 2, y: self.size.height / 2 - 100),
|
||||
onButtonPress: {
|
||||
if BackgroundComponent.isMovingBackgroundEnabled == true {
|
||||
BackgroundComponent.isMovingBackgroundEnabled = false
|
||||
} else {
|
||||
BackgroundComponent.isMovingBackgroundEnabled = true
|
||||
}
|
||||
|
||||
|
||||
}))
|
||||
|
||||
entityManager.add(Background(size: self.size))
|
||||
|
Loading…
Reference in New Issue
Block a user