From 284cf1381b32a1755180bd97b5d512ed8958649e Mon Sep 17 00:00:00 2001 From: 127-Z3R0 <81heti1bif@hft-stuttgart.de> Date: Sun, 10 May 2020 21:16:28 +0200 Subject: [PATCH] add button to SettingsScene for Background Movement --- .../GoldWars/Components/BackgroundComponent.swift | 11 +++++++---- GoldWars/GoldWars/SettingsScene.swift | 13 +++++++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/GoldWars/GoldWars/Components/BackgroundComponent.swift b/GoldWars/GoldWars/Components/BackgroundComponent.swift index 7239741..ce5c16a 100644 --- a/GoldWars/GoldWars/Components/BackgroundComponent.swift +++ b/GoldWars/GoldWars/Components/BackgroundComponent.swift @@ -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,10 +28,12 @@ class BackgroundComponent: GKComponent{ } func update(){ - for node in nodes{ - node.position.x -= 2 - if node.position.x < -(size.width) { - node.position.x += (size.width) * 3 + if BackgroundComponent.isMovingBackgroundEnabled == true { + for node in nodes{ + node.position.x -= 2 + if node.position.x < -(size.width) { + node.position.x += (size.width) * 3 + } } } } diff --git a/GoldWars/GoldWars/SettingsScene.swift b/GoldWars/GoldWars/SettingsScene.swift index ae91cce..e106848 100644 --- a/GoldWars/GoldWars/SettingsScene.swift +++ b/GoldWars/GoldWars/SettingsScene.swift @@ -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))