swift change SKSpriteNode image in SKScene class

user3752276 picture user3752276 · Dec 17, 2014 · Viewed 8.8k times · Source

I defined SKSpriteNode under SKScene class, how can i change the SKSpriteNode image afterwards, for example:

class GameScene: SKScene {

  var player = SKSpriteNode(imageNamed: "player")
}

I want to change the image from "player" to "player1" during some action. I do not inherit SKNode class, so i can not use SKTexture method to do it.

Answer

67cherries picture 67cherries · Dec 17, 2014

SKScene is a subclass of SKNode so you do in fact inherit it. You can use SKTexture to change the image like this:

player.texture = SKTexture(imageNamed: "player1")