Access array in GameScene from SKSpriteNode class instance?

笑着哭i 提交于 2019-12-02 07:40:22

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!