Swift 1.2 bug: different behavior between iOS 7.1 and 8.3 while removing SKSpriteNode from parent

China☆狼群 提交于 2019-12-24 04:04:35

问题


Sample project: https://github.com/wilkinho/RemoveFromParentTest

Swift version: 1.2 Xcode version: 6.3

I try to remove a SKSpriteNode from its parent and add it back to the SKScene within its own SKAction run block (or callback). The result differs in iOS 7.1 and 8.3.

In iOS 7.1, after touching the device, the console prints:

sprite.parent:Optional(<SKScene> name:'(null)' frame:{{0, 0}, {320, 568}})
sprite.scene:nil
sprite2.parent:Optional(<SKScene> name:'(null)' frame:{{0, 0}, {320, 568}})
sprite2.scene:Optional(<SKScene> name:'(null)' frame:{{0, 0}, {320, 568}})

In iOS 8.3, after touching the device, the console prints:

sprite.parent:Optional(<SKScene> name:'(null)' frame:{{0, 0}, {320, 568}})
sprite.scene:Optional(<SKScene> name:'(null)' frame:{{0, 0}, {320, 568}})
sprite2.parent:Optional(<SKScene> name:'(null)' frame:{{0, 0}, {320, 568}})
sprite2.scene:Optional(<SKScene> name:'(null)' frame:{{0, 0}, {320, 568}})

The first SpriteNode lost SKScene reference in iOS 7.1 but not in iOS 8.3. I think this is a bug of Swift 1.2 and I need to workaround it in my project. Any insights will be appreciated.

来源:https://stackoverflow.com/questions/29726606/swift-1-2-bug-different-behavior-between-ios-7-1-and-8-3-while-removing-sksprit

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