0

In this code, I am trying to have a variable that holds the random number between 0-3. Then, I want the ball sprite to be assigned to one of the 4 images, chosen randomly by the randomizer variable.

I have an error with this code saying

Instance member 'randomizer' cannot be used on type 'GameScene'

var randomizer = (arc4random_uniform(3))

var ball = SKSpriteNode(imageNamed: "ball\(randomizer)")
  • This is not objective c, it would be `"ball\(randomizer)"` – Knight0fDragon Aug 30 '16 at 12:28
  • I fixed the code but still get an issue saying with the 'Instance Member 'randomizer' @Knight0fDragon – user6686513 Aug 30 '16 at 16:43
  • well is this all public variables? You can't do it this way because randomizer is an instance variable, and at compile time, your instance does not exist. you would need to assign it in the init method to get it to work the way you want it to – Knight0fDragon Aug 30 '16 at 17:04
  • Yes, these are all public variables. Where would I create the init method then? Is it possible to create it outside the didMoveToView() method? @Knight0fDragon – user6686513 Aug 30 '16 at 18:03
  • ... I am sorry, this is not the place for these questions, go read intro to swift books and tutorials – Knight0fDragon Aug 30 '16 at 18:05

0 Answers0