0

I have just started making a new game in Swift with SpriteKit, but it is coming up with an error telling me that the none of my member variables exist. I can't understand why it is doing this, because I clearly created the member variables.

Am I missing something?

Here is my current GameScene.swift:

My current GameScene.swift

septicorn
  • 142
  • 1
  • 12
  • 1
    See also http://stackoverflow.com/questions/25854300/how-to-initialize-properties-that-depend-on-each-other. – Martin R Sep 03 '15 at 14:44

2 Answers2

1

You're getting an error because, even though you specified a default value for bluePortal, at the time you specify a default value for portal no variable named bluePortal actually exists. Default values are values that will be assigned only when an actual instance of the class is created. I suggest you create an init() method where you initialise bluePortal.

P.S. Next time, please paste your code instead of using a screenshot. It'll help other users troubleshoot your problem faster.

MustangXY
  • 358
  • 2
  • 16
0

Please add var portal : SKSpriteNode! = SKSpriteNode(texture:bluePortal) inside some method or just declare it above and use it inside some method.

iAnurag
  • 9,286
  • 3
  • 31
  • 48