Why am I getting an error in this code, it seems perfectly normal to me. I declare \'hills\' as a variable but I am still getting the error \"Expected declaration\" for both
I suspect the reason for the Expected Declaration message is that you have placed this code inside of a class without putting it inside of a method. The example below compiles, but it gives the same error you are seeing if it is not included inside of the setup
method:
class MyNode: SKSpriteNode {
func setup() {
var bg = SKSpriteNode(imageNamed: "sky")
bg.position = CGPointMake(bg.size.width / 2, bg.size.height / 2)
self.addChild(bg)
var hills = SKSpriteNode(imageNamed: "hills")
hills.position = CGPointMake(hills.size.width / 2, 300)
self.addChild(hills)
}
}