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

It may take some time for my scene to load, and I want to show the loading animation, however, everything is blocked. Is there a way to load the following asynchronous script and get a callback when it's ready?

+4
source share
1 answer

You can schedule a block for parallel execution using dispatch_async . Load the scene in an asynchronous block, then execute the callback method in the main thread, for example:

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

Source: https://habr.com/ru/post/1525982/


All Articles