问题描述
我已经在GameScene实例中创建了一个数组,并将其填充到didMove(以查看:)...
I've created an array in my GameScene instance, and populated it inside didMove(to view: )...
如何从SKSpriteNode实例访问该数组中的值?
From an instance of an SKSpriteNode, how do I access a value in that array?
据我所知,从模板来看,我没有引用GameScene实例.但是我也可以在这方面走开.
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.
推荐答案
虽然您链接的答案可以解决您的问题,但它会在节点和场景之间引入耦合,您以后可能会后悔.一种更强大的解决方案将允许节点引用碰巧正在运行的任何场景,这是iOS中一种常见的设计模式,称为delegate
模式.
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.
这篇关于从SKSpriteNode类实例访问GameScene中的数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!