SKScene not initializing with file

I'm trying to get a new tvOS SpriteKit project started, but it appears there is a bug preventing me from doing so. The default code example when starting a new project of this type doesn't actually work properly (no Hello World in Chalkduster). It appears as though the GameScene.sks file isn't actually being found here:


if let scene = SKScene(fileNamed: "GameScene") as? GameScene {

//Some code

}


Anyone else having this problem and has maybe found a work around?

Accepted Answer

Took a fresh look at it this morning and found the solution,


change:

if let scene = SKScene(fileNamed: "GameScene") as? GameScene {


to:

if let scene = GameScene(fileNamed: "GameScene") {


and everything works

This sort of worked for me. After I removed the GameScene casting, it just casts as SKScene and never loads the GameScene didMoveToView or touchesBegan.


I hade to do:


let scene = SKScene(fileNamed: "GameScene.sks")!


notice the if condition is removed


I think this bug in tvOS because the same code runs fine on iOS.

Please file a bug report on bugreport.apple.com under tvOS SDK.

I have this same issue. I found that if I entered the module name on the SKS file it worked without changing the boilerplate code.



Problem I have now is that I want to use the same SKS file in an iOS target AND a tvOS target but the targets get different module names.


It seems to work just fine for that one module tho'.


UPDATE:


Found that the following code works:


if let scene = GameScene(fileNamed: "GameScene")

Have logged bug: 23156052

SKScene not initializing with file
 
 
Q