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?
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];
});
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With