How to load a scene async so you can have a loading screen?

妖精的绣舞 提交于 2019-12-21 02:35:16

问题


My scene loads can take a while, and I want to be able to show a loading animation, however, everything locks up. Is there a way to load the next scene async and get a callback when its ready?


回答1:


You can schedule a block for concurrent execution using dispatch_async. Load scene in async block then perform callback method on the main thread like this:

__weak MyClass *weakself = self; 
dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void){
    //Background thread
    //Load scene here
    dispatch_async(dispatch_get_main_queue(), ^(void){
        //Main thread
        //Call your callback method here
        [weakself sceneLoaded:loadedScene];
    });
});


来源:https://stackoverflow.com/questions/21653679/how-to-load-a-scene-async-so-you-can-have-a-loading-screen

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