ios - 无法设置 SKView backgroundColor

标签 ios objective-c ios7 sprite-kit skview

我有一个问题,我的 SKView 的背景颜色(灰色)在场景出现之前短暂显示。

我试图通过 Storyboard 编辑器和我的 Controller (self.skView.backgroundColor = [SKColor blueColor]) 手动设置它,但它仍然是灰色的。这不是可以覆盖的属性吗?

更新#1

这里有一些关于发生的事情的解释:

  1. viewDidLoad 被调用,skView 呈现在屏幕上,背景为灰色(skView.scene 尚未设置)。
  2. 我加载了游戏的所有 Assets (大约需要 1 秒),在此期间灰色背景可见。
  3. 加载 Assets 后,我加载场景并呈现它(灰色屏幕被替换为场景内容)

View Controller

- (void)viewDidLoad
{
    [self.activityIndicator startAnimating];
    [self authenticatePlayer];

    self.skView.backgroundColor = [SKColor blueColor];

    // During this time the grey screen is visible as the assets are being loaded and take ~1 second
    // self.skView.scene is NULL here so I cannot set the backgroundColor...

    [GamePlayScene loadSceneAssetsWithCompletionHandler:^{
        [self.activityIndicator stopAnimating];
        self.activityIndicator.hidden = YES;

        CGSize viewSize = self.skView.bounds.size;

        self.gamePlayScene = [[GamePlayScene alloc] initWithSize:viewSize];
        self.adView.autoresizingMask = UIViewAutoresizingFlexibleWidth;

        [self.skView presentScene:self.gamePlayScene];

    }];
    ...

最佳答案

恐怕您要么必须先完成最基本的设置(例如设置 backgroundColor),然后加载其余的场景,要么展示一个“正在加载”的场景,直到游戏场景加载完毕,然后替换它。

关于ios - 无法设置 SKView backgroundColor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22053035/

相关文章:

ios - 为什么我的 NSURLConnection 报告不正确的 expectedContentLength

iphone - MFMessageComposeViewController 未调用其委托(delegate)方法

ios - 向后滑动太快时 UIButton 的标题神秘消失

ios - 如何使用一个数组作为另一个数组的谓词?

碰撞所需版本后,iOS 应用未出现在应用商店搜索结果中

ios - 没有 OpenGL 的 iOS 上的硬件加速缩放

objective-c - 清除 NSTableView 内容

ios - 下载并打开 PDF 文件失败,出现错误未能在 ios 中找到 PDF 标题

IOS 5.0 - NSURLConnection 工作但在完成之前返回 Null

ios - UITableViewCell 中每个 WebView 的 ActivityIndi​​cator