问题
I've created an array in my GameScene instance, and populated it inside didMove(to view: )...
From an instance of an SKSpriteNode, how do I access a value in that array?
So far as I know, from the template, I don't have a reference to the GameScene instance. But I could be way off on this, too.
回答1:
While the answer you've linked to will solve your problem, it introduces a coupling between the node and the scene which you might regret later. A more robust solution would allow the node to reference whatever scene it happens to be running in, which is a common design pattern in iOS called delegate
pattern.
来源:https://stackoverflow.com/questions/40015729/access-array-in-gamescene-from-skspritenode-class-instance