本文介绍了sceneDidLoad被调用两次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Xcode 8,Swift 3,我使用启用了实体的游戏模板创建一个iOS应用程序.我注意到,即使只使用addChild一次,我仍然看到一些初始精灵的双节点计数.

Using Xcode 8, swift 3 and I create a iOS application using the game template with entities enabled. I notice I was seeing double node count for some initial sprites even though I only used addChild once.

我添加了

override func sceneDidLoad() {
print(#function) ... }

不知道为什么为什么要两次调用它.

to the code and no idea why this is being called twice.

日志文件...

2016-09-20 10:21:31.482 MMDecon1[3295:791435] SKUtil.m: MGGetBoolAnswer is not available in the simulator.
sceneDidLoad()
sceneDidLoad()

我添加了

override func didMove(to view: SKView) {..}

并将我的初始化代码放在此处作为临时修复程序.

and put my initialisation code in here as a temporary fix.

有人知道为什么使用实体的默认游戏应用代码将sceneDidLoad()触发两次吗?

Does any one know why sceneDidLoad() is being fired twice with the default game app code using entities?

推荐答案

通常,仅一次调用sceneDidLoad.但是,如果发送了内存警告,则UIViewController会释放其场景,如果视图控制器不可见,则将其设置为nil.下次场景出现时,视图控制器将重新加载场景并再次调用sceneDidLoad.

Normally, sceneDidLoad is only called one time. However, if a memory warning is sent then UIViewController releases its scene and sets it to nil if the view controller isn't visible. The next time that the scene appears the view controller will reload the scene and call sceneDidLoad again.

您必须假定sceneDidLoad可以被多次调用.

You have to assume that sceneDidLoad can be called multiple times.

实施didReceiveMemoryWarning并记录或设置断点以查看发生的情况.

Implement didReceiveMemoryWarning and log or set a breakpoint to see what is happening.

这篇关于sceneDidLoad被调用两次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-28 18:41