2

I got an animation of blocks changing the colors, when the there's a click in the block, the color animation stops and I want to get the color that the block stopped.

I noticed that a SKSpriteNode have a SKTexture attribute, but I can't reference it by calling:

node.texture

I get an error that the node does not have a membed named 'texture', but in debugger the texture is there:

<SKSpriteNode> name:'(null)' texture:[<SKTexture> 'orange@2x.png' (40 x 40)] position: {604.6412353515625, 205.83619689941406} size:{20, 20} rotation:0.0

I want to get the 'orange@2x.png' name of a Node, so I can compare it later.

2 Answers2

4

You probably only have the node as an SKNode, which doesn't have the texture property. You should be able to use an optional binding to cast to SKSpriteNode, like this:

if let spriteNode = node as? SKSpriteNode {
    println(spriteNode.texture)
}
Nate Cook
  • 92,417
  • 32
  • 217
  • 178
0

Sprite-Kit Change Image of Node when screen gets touched

First answer may help, the way he did it seems easy and logical.

Make it SpriteNode instead of Node. Define the textures first as variables, then assign these variables to the .texture of the node.

Community
  • 1
  • 1
Betkowski
  • 491
  • 1
  • 4
  • 17