Search code examples
iosswiftsprite-kitskspritenodesktexture

Update / Change the image of SKSpriteNode


Is it possible to update/change the image of an SKSpriteNode?
The code below does not work:

var boss1 = SKSpriteNode(imageNamed: "boss1.png")
boss1 = SKSpriteNode(imageNamed: "boss2.png")

Solution

  • Once you created the SKSpriteNode

    var boss1 = SKSpriteNode(imageNamed: "boss1.png")
    

    you can update the texture property like that

    boss1.texture = SKTexture(imageNamed: "boss2.png")
    

    Here's an example from my Playground

    enter image description here