12

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

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

更新#1

以下是关于发生的事情的一些解释:

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

视图控制器

- (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];

    }];
    ...
4

4 回答 4

3

恐怕您要么必须完成最基本的设置(例如设置背景颜色)来呈现场景,然后加载其余部分,要么呈现“加载”场景直到游戏场景加载,然后替换它。

于 2014-02-26T21:52:10.423 回答
0

I think you have mistaken it for the SKScene property of the same name:

self.scene.backgroundColor = [SKColor blueColor];

Note that self.scene (also self.view) will be nil until after the node has been added as child to another node (that is already part of the scene graph) respectively until the scene was presented.

于 2014-02-26T21:23:03.543 回答
0

You should be able to set the SkView background colour in the presenting view controllers viewDidLoad - prior to presenting the view. Is this not happening?

Providing you've added it to a parent node

于 2014-02-26T21:23:06.790 回答
0

使用精灵套件的基本模板,我可以在 GameViewController.m 文件中使用以下代码将背景设置为黑色:

- (void)viewDidLoad
{
[super viewDidLoad];

// Configure the view.
SKView * skView = (SKView *)self.view;
skView.showsFPS = YES;
skView.showsNodeCount = YES;
/* Sprite Kit applies additional optimizations to improve rendering performance */
skView.ignoresSiblingOrder = YES;

// Create and configure the scene.
GameScene *scene = [GameScene sceneWithSize:skView.bounds.size];
scene.scaleMode = SKSceneScaleModeAspectFill;
scene.backgroundColor = [UIColor blackColor];

// Present the scene.
[skView presentScene:scene];
}

不确定这是否正是您要寻找的,但它摆脱了似乎并没有消失的灰色背景。在您的情况下,我认为您希望在初始化场景后设置“gamePlayScene”背景颜色属性。

希望这可以帮助!

于 2014-11-22T04:57:59.017 回答