I'm planning to make an arcade game in which the screen is divided in two halves. Each of this half's background can vary each time the player starts the game.
I wanted to design my backgrounds into different .sks files, and then randomly load two of them into my GameScene by using the SKReferenceNode programmatically.
The trouble is that the sks content is treated as an SKScene, and so it obviously can't be added as a child of my scene:
class GameScene: SKScene {
override func didMove(to view: SKView) {
let upperBackground = SKReferenceNode(fileNamed: "Caribbeans")!
addChild(upperBackground)
}
}
I'm wondering if there's a way to make the compiler treat my SKReferenceNode as a SKSpriteNode, but trying to downcast doesn't work since SKReferenceNode and SKSpriteNode are unrelated.
I know that it works whenever I create a bigger sks scene, drag two SKReferenceNodes and then set their references to a single background, but the problem is that I want to make a random selection of two backgrounds that vary each time, so I must find a way to get around this trouble programmatically and not through the scene editor.
Any suggestions?