本文介绍了从 SKSpriteNode 类实例访问 GameScene 中的数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的 GameScene 实例中创建了一个数组,并将其填充到 didMove(to view: )...

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 中的数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 09:16