【发布时间】:2015-03-30 23:19:17
【问题描述】:
我试图弄清楚这两个示例之间的区别以及 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
}];
【问题讨论】:
标签: ios objective-c sprite-kit grand-central-dispatch sktextureatlas