I have a SKSpritnode table for a background in a game and I want the background to change as the players points reach a certain level eg every 20 points. I use a range operator as shown below. The code below builds and runs but background doesn't change.
Code Block func setupTable(){ if(0...19).contains(playerScore) { let table = SKSpriteNode(imageNamed: "ovaloffice") addChild(table) table.position = CGPoint(x: size.width/2, y: size.height/2) table.zPosition = -1} else if(20...39).contains(playerScore) { let table = SKSpriteNode(imageNamed: "austin") addChild(table) table.position = CGPoint(x: size.width/2, y: size.height/2) table.zPosition = -1} else { let table = SKSpriteNode(imageNamed: "bond") addChild(table) table.position = CGPoint(x: size.width/2, y: size.height/2) table.zPosition = -1} func addPlayerScore() { playerScore += 1 playerLabel.text = "Arn: \(playerScore)" }
Sorry, not being clear enough. Can you see the indentation of my code? I make my code properly indented and copied the code into post keeping the indentation.I had to put the Extension out of the scope
You should better care about indentation of your code.
Use Cmd-A (Select All) and Ctrl-I (Re-Indent)
Starting from column #1 in my code means the definition is not in any other types.
Put the definition of enum TableType and the extension into some Swift file of your project, but not inside GameScene or any other types.
Move them out of GameScene.