tucker2121
tucker2121

Reputation: 58

SKView/SKScene won't change background color

I seem to have run into a particularly weird problem in a game I am developing. This game contains three game types, each of which use an SKView as the display for the game. The first two game types (called normal and chess) properly change background colors in code like this:

    // Create and configure the scene.
    M2ChessScene *scene = [M2ChessScene sceneWithSize:yourGameView.bounds.size];
    scene.scaleMode = SKSceneScaleModeFill;
    [scene setBackgroundColor:[UIColor clearColor]];
    // Present the scene.
    [yourGameView presentScene:scene];
    [self updateScore:0];


    _scene = scene;
    _scene.delegate = self;
    _scene.isPrimaryView = YES;

This creates the scene and sets the background to clearColor, and it works. However, in my third game type (which has two scene views) the same code (which is repeated twice, once for each scene), does not work, and I end up with a black background instead of a clear one. What am I doing wrong? I don't see how the same code could not work in one instance and not in another in almost identical classes (in fact the code for this class was copied from the chess class and repeated for the second view (with variable name edits)).

Any help will be greatly appreciated.

Upvotes: 0

Views: 862

Answers (2)

tucker2121
tucker2121

Reputation: 58

Turns out I was trying to set it to transparent, which is not allowed in iOS 7, so it was defaulting to black.

Upvotes: 0

CodeSmile
CodeSmile

Reputation: 64477

On iOS you can have only one active SKView at a time. While technically working without errors, one of the two views will not or only very rarely render its contents and update its nodes and physics.

If you need a split-screen display you'll have to implement it with a single SKView and SKScene.

Upvotes: 1

Related Questions