I created this SpriteKitNode:
let examp = examps[examps.count-1] // examps is a global array with SKNodes inside of it
But when I try to change its texture I receive this error:
examp.texture = SKTexture(imageNamed: "examp2")
Value of type 'SKNode' has no member 'texture'
However, it has a value of 'texture' so I don't know what the solution is.
examps
is [SKNode]
. This means that examp
is SKNode
, not SKSpriteNode
even if examps[examps.count-1]
happens to hold an SKSpriteNode
.
In order to access the texture
property, you need to cast the result of examps[examps.count-1]
to an SKSpriteNode
.
if let examp = examps[examps.count-1] as? SKSpriteNode {
examp.texture = SKTexture(imageNamed: "examp2")
}