Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

swift change SKSpriteNode image in SKScene class

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.

like image 563
user3752276 Avatar asked Dec 17 '14 02:12

user3752276


1 Answers

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")
like image 172
67cherries Avatar answered Nov 10 '22 04:11

67cherries