sceneDidLoad being called twice?

谁说我不能喝 提交于 2019-12-03 18:51:40

问题


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.

I added

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

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

log file...

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

I added

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

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

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


回答1:


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.

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

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



来源:https://stackoverflow.com/questions/39590602/scenedidload-being-called-twice

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