0

Do I have to set the array to a specific type so that it will store the images or is it something else. The images are stored in the Images.xcassets

class GameScene: SKScene {

   var blueTexture = SKTexture(imageNamed: "BlueBall.png")
   var greenTexture = SKTexture(imageNamed: "GreenBall.png")
   var redTexture = SKTexture(imageNamed: "redTexture.png")

   var array = [blueTexture, greenTexture, redTexture]
   //error: GameScene does not have a member called blueTexture
   //this goes for the other textures as well
Miles Militis
  • 147
  • 1
  • 7
  • Duplicate of http://stackoverflow.com/questions/25855137/viewcontroller-type-does-not-have-a-member-named or http://stackoverflow.com/questions/25854300/how-to-initialize-properties-that-depend-on-each-other (and probably some more) – pick your choice! – Martin R Jul 24 '15 at 13:26

1 Answers1

1

This is because you can't access other properties during initialization, so you could replace you current code with this:

var blueTexture = SKTexture(imageNamed: "BlueBall.png")
var greenTexture = SKTexture(imageNamed: "GreenBall.png")
var blueTexture = SKTexture(imageNamed: "BlueBall.png")

var array:[SKTexture]!
override func didMoveToView(view: SKView) 
{
    array = [blueTexture,greenTexture,blueTexture]      
}

Also, you made two blueTextures.

LuckyStarr
  • 1,468
  • 2
  • 26
  • 39
Epic Defeater
  • 2,107
  • 17
  • 20