How to retrieve an array with many spritekitnodes?

25 views Asked by At

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)
}
1

There are 1 answers

0
Kenny Chong On

Found my own answer. Loop through the entire array of SpritekitNode in the Update function.