這裏是我的方法:
在Interface Builder中添加SKView
,導入圖像,大白活動指示到GameSceneViewController
:

爲添加的控件添加網點GameSceneViewController
:
@interface GameSceneViewController : UIViewController
@property (nonatomic, weak) IBOutlet SKView *skView;
@property (weak, nonatomic) IBOutlet UIImageView *loadingScreen;
@property (weak, nonatomic) IBOutlet UIActivityIndicatorView *activityIndicator;
@end
在您的SKScene
a DD類方法,它加載的所有資產的場景:
+(void)loadSceneAssetsWithCompletionHandler:(AGAssetLoadCompletionHandler)handler {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
// Load the shared assets in the background.
[self loadSceneAssets];
if (!handler) {
return;
}
dispatch_async(dispatch_get_main_queue(), ^{
// Call the completion handler back on the main queue.
handler();
});
});
}
其中AGAssetLoadCompletionHandler
在GameScene.h
定義爲
/* Completion handler for callback after loading assets asynchronously. */
typedef void (^AGAssetLoadCompletionHandler)(void);
同樣的方式使用蘋果在他們Sprite Kit Adventure Game。
最後,GameSceneViewController
的viewWillAppear
方法:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.activityIndicator startAnimating];
if (!self.skView.window) {
[self.view addSubview:self.skView];
}
[GameScene loadSceneAssetsWithCompletionHandler:^{
GameScene *scene = [[GameScene alloc] initWithSize:self.skView.bounds.size];
scene.scaleMode = SKSceneScaleModeAspectFit;
[self.skView presentScene:scene transition:[SKTransition crossFadeWithDuration:1]];
[self.activityIndicator stopAnimating];
[UIView animateWithDuration:1.0 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
self.loadingScreen.alpha = 0.0f;
} completion:NULL];
}];
}
韋恩·哈特曼的答案很可能你需要的東西,但它是可能的(可能)你的一些延遲5秒的來源於事情發生在我這應該發生在後臺。例如,如果您正在加載資源,則無需阻止UI線程。你可以開始你的微調,然後在後臺加載你的內容,並在完成後回調主線程加載你的新場景。 – dokkaebi
@dokkaebi這聽起來似乎合理。我可以在後臺線程中執行場景的alloc init,然後在主線程中使用它嗎? – Dvole
這取決於在初始化期間發生了什麼。如果它不觸及視圖層次結構,那應該沒問題。我沒有使用精靈套件,所以你必須仔細檢查它是如何工作的。 – dokkaebi