I have previously spent a lot of time using cocos2d, and got used to the convenience of tags, which are also available on UIView objects, but currently I started a project using spritekit and cannot find an equivalent. Thus my question, does anyone know if there is any kind of equivalent to it for SKSpriteNode/SKNode objects?
You can use the
name property of
From the documentation:
Used to assign a name to a node for later reference. When choosing a name for a node, you should decide whether each node gets a unique name or whether some nodes will share a common name. If you give the node a unique name, you can find the node later by calling the
childNodeWithName:method. If a name is shared by multiple nodes, the name usually means that these are all a similar object type in your game. In this case, you can iterate over those objects by calling the
Sprite got something way better. Instead of just a tag, within a SKNode you can set a whole dictionary. Say hello to your new friend
let myNode : SKSpriteNode = SKSpriteNode(imageNamed: "make-america-great-again") myNode.userData = [ "keyA" : "blahblah", "keyB" : 17.0 ]; NSLog("OMFG is this \(myNode.userData?["keyA"]) and \(myNode.userData?["keyB"]) for real!??")