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.
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")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With