add button to SettingsScene for Background Movement

This commit is contained in:
127-Z3R0 2020-05-10 21:16:28 +02:00
parent 40890f4e37
commit 284cf1381b
2 changed files with 20 additions and 4 deletions

View File

@ -12,6 +12,7 @@ class BackgroundComponent: GKComponent{
var nodes = [SKSpriteNode]() var nodes = [SKSpriteNode]()
let size: CGSize let size: CGSize
static var isMovingBackgroundEnabled: Bool = true
init(size: CGSize) { init(size: CGSize) {
self.size = size self.size = size
@ -27,10 +28,12 @@ class BackgroundComponent: GKComponent{
} }
func update(){ func update(){
for node in nodes{ if BackgroundComponent.isMovingBackgroundEnabled == true {
node.position.x -= 2 for node in nodes{
if node.position.x < -(size.width) { node.position.x -= 2
node.position.x += (size.width) * 3 if node.position.x < -(size.width) {
node.position.x += (size.width) * 3
}
} }
} }
} }

View File

@ -36,6 +36,19 @@ class SettingsScene: SKScene {
SoundManager.startMenuMusic() 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)) entityManager.add(Background(size: self.size))