1

I have a Swift 4.2 SpriteKit scene and I want to programatically change the texture of an SKSpriteNode. How do I access the SKSpriteNode contained in the SKNode to change the texture? Here is my code:

 @IBOutlet weak var spritekitsceneFG: WKInterfaceSKScene!  

   var SpriteTick1 = SKNode()

   SpriteTick1 = (spritekitsceneFG.scene?.childNode(withName: "SKSpriteTick1"))!

   Want to change texture here!   

   print(SpriteTick1)

Printing out the SKNode gives the following output:

<SKSpriteNode> name:'SKSpriteTick1' texture:[<SKTexture> 'tick' (64 x 64)] position:{-48.000137, -56.000198} scale:{1.00, 1.00} size:{48, 48} anchor:{0.5, 0.5} rotation:0.00

I want to be able to programatically change the texture here, the texture is called 'tick'

Robin
  • 373
  • 1
  • 3
  • 20
Arkon3
  • 63
  • 6

1 Answers1

1

Ok I found A way to do it like this. Any better ideas much welcomed.

   var SpriteTick1 = SKSpriteNode()
   SpriteTick1 = (spritekitsceneFG.scene?.childNode(withName: "SKSpriteTick1"))! as! SKSpriteNode
   let textureCross = SKTexture(imageNamed: "cross")
   SpriteTick1.texture = textureTick
Arkon3
  • 63
  • 6