I store an array of spriteNode into an array spacecraftArray with the code as follows. Later on, I need to access a specific item in the array. How do I do it?
There is no unique identifier or index that I can use to direct access a node later selected by my user.
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) {
let spacecraft = SKSpriteNode(imageNamed: "spacecraft")
spacecraft.createUnit(gameSceneCell: gameSceneCell)
spacecraftArray.append(spacecraft)
self.addChild(spacecraft)
}
Found my own answer. Loop through the entire array of SpritekitNode in the Update function.