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,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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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