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

后端 未结 1 1690
庸人自扰
庸人自扰 2021-02-10 13:43

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

1条回答
  •  太阳男子
    2021-02-10 14:34

    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];
        });
    });
    

    0 讨论(0)
提交回复
热议问题