我试图弄清楚这两个示例之间的区别以及 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
}];