sceneDidLoad being called twice?

2019-02-01 10:05发布

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条回答
爷、活的狠高调
2楼-- · 2019-02-01 10:49

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.

查看更多
登录 后发表回答