swiftscenekittvos

How to ensure current SKScene has fully loaded before engaging it with the GamePad Controller?


How to ensure current SKScene has fully loaded before engaging it with the GamePad Controller?

The problem is this = when stopping sound is involved when I do switch SKScenes, if I press the buttons of the GamePad Controller (which cycle thru these other SKScenes) too fast, the movement of the Game Pieces fails to resume when I return to the Game Scene after the above cycling.

This problem occurs only with the os(tvOS) version, but not with the iPad version. And the reason for this distinction is that each SKScene for the iPad has to fully load due to the fact that the button I press to switch SKScenes is at the top-left corner of the iPad -- so, by definition, by the time I have access to this button, the current SKScene has fully loaded.

By definition, there is no such button for os(tvOS).

Given this button’s absence, I think I need the Swift version of jQuery’s

$(document).ready (function() {.

Any help will be appreciated to the rafters ...


Solution

  • SUCCESS ...

    I discovered that when you use a SKTransition whenever calling presentScene just for os(tvOS), that the above OH-OH happens.

    Again, no such OH-OH for os(iOS) ??

    SO .. just eliminate the SKTransition for os(tvOS), and all is good.

    I'm not particularly happy about ditching the SKTrnsition, but at least now I know the solution.

    func presentScene(_ theScene: SKScene) {
                
        theScene.scaleMode = .resizeFill
        
        if let skView = self.view as? SKView {
            skView.ignoresSiblingOrder = true
            skView.showsFPS = true
            skView.showsNodeCount = true
                    
    #if os(iOS)
            let theTransition = SKTransition.doorway(withDuration: 2.0)
            skView.presentScene(theScene, transition: theTransition)
    #elseif os(tvOS)
            skView.presentScene(theScene)
    #endif
        }
        
    }   // presentScene