Я пытаюсь понять, в чем разница между этими двумя примерами и как работает preloadTextureAtlases :withCompletionHandler. Вот код:
//GameScene.m
-(void)didMoveToView:(SKView *)view {
//First I create an animation, just a node moving from one place to another and backward.
//Then I try to preload two big atlases
[SKTextureAtlas preloadTextureAtlases:@[self.atlasA, self.atlasB] withCompletionHandler:^{
[self setupScene:self.view];
}];
Я предполагаю, что preloadTextureAtlases выполняет загрузку в фоновом потоке, потому что моя анимация плавная?
Но есть ли отличия (или это может быть как-то проблематично) для вызова preloadTextureAtlases из фонового потока? Как это:
//GameScene.m
- (void)loadSceneAssetsWithCompletionHandler:(CompletitionHandler)handler {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
[SKTextureAtlas preloadTextureAtlases:@[self.atlasA, self.atlasB] withCompletionHandler:^{
dispatch_async(dispatch_get_main_queue(), ^{
[self setupScene:self.view];
});
}];
if (!handler){return;}
dispatch_async(dispatch_get_main_queue(), ^{
handler();
});
});
}
А затем вызовите этот метод из didMoveToView:
[self loadSceneAssetsWithCompletionHandler:^{
NSLog(@"Scene loaded");
// Remove loading animation and stuff
}];