0

I'm simply trying to set a float value to a variable like the code below, but xcode won't let me go on.

import SpriteKit

class GameScene: SKScene {

    let frameWidth = CGFloat(self.frame.width)
}

It keeps returning me this:

Value of type 'NSObject -> () -> GameScene' has no member 'frame'


I looked for this error everywhere, but nothing helped me. Would anyone know what I can to do make it work?

Thanks in advance,
Luiz.

Luiz
  • 1,275
  • 4
  • 19
  • 35
  • You could just use GameScene.frame.width in your code instead of making a new equivalent property named GameScene.frameWidth. The problem above is trying to access a member property before the object exists. Would need to have your own init() function, and set your frameWidth after calling super.init() – rebusB Jun 06 '16 at 22:18
  • That's how my code was, but I wanted to make the it "cleaner". By the way, the first question above (which I didn't know of its existence) has the answer. Thank you for your attention =) – Luiz Jun 06 '16 at 22:31

0 Answers0