2 Replies
      Latest reply on Dec 5, 2018 5:43 AM by abanet
      froimgg Level 1 Level 1 (0 points)

        Hi

         

        I'm building a SpriteKit app and now i have a problem with the SKTransitions

         

        First, i built the whole app on one ViewController, but i notices fast that this isn't a good solution (it's my first app).

         

        So i made a MenuViewController and a GameViewController, but when i outsourced

         

                let scene = GameScene(size: view.bounds.size)
        
                let skView = view as! SKView
                skView.ignoresSiblingOrder = true
                scene.scaleMode = .resizeFill
                scene.delegate = self
        
                skView.presentScene(scene)
        
        
        
        

         

        from MenuViewController (MainViewController) to GameViewController I had the problem that the Transition from GameScene to GameOverScene (another SKScene) didn't work. It's strange because i only changed the ViewController and i didn't do anything else on the Code.

         

        I hope you can help me (if you need any other information, please let me know.)

         

        FroiMgg

         

         

        //Edit

        I found out that the problem should be in the transition, because if i delete the transition (view?.presentScene(nextScene as! SKScene)) everything works fine.

         

        Here's the code of the Transition:

        func revealGameOverScreen() {
                let nextScene: AnyObject!
                let direction: SKTransitionDirection!
                if secondsOfLife > highScore {
                    nextScene = GameHighScoreScene(size: self.size, scoreOfLife: secondsOfLife)
                    direction = SKTransitionDirection.down
                    highScore = secondsOfLife
                } else {
                    nextScene = GameOverScene(size: self.size, scoreOfLife: secondsOfLife)
                    direction = SKTransitionDirection.up
                }
                let reveal = SKTransition.push(with: direction, duration: 2)
                view?.presentScene(nextScene as! SKScene, transition: reveal)
            }
        
        
        

         

        //Edit 2

         

        Someone else had exaclty the same problem with iOS 9:

        https://forums.developer.apple.com/message/85497#85497

        It's difficult for me to make a workarround, because it's a SKTransition.push (and it's really important for the game).

        I can't delete the ViewControllers because i use an advertising framework and GameCenter (It wasn't possible for me to use these in a SKScene).

        • Re: SKScene transition fail
          CartoonSmart.com Level 3 Level 3 (270 points)

          Maybe rewrite it slightly ? You probably don't need nextScene to start as AnyObject!

           

          if let nextScene = GameScene(fileNamed: "NextScene") {
                          nextScene.scaleMode = .aspectFill
                          self.view?.presentScene(nextScene, transition: reveal )
                      
                      }
          

           

          You can setup your transition variable outside of that block or within it. And the fileNamed: property could be a variable of course. Might help.

          • Re: SKScene transition fail
            abanet Level 1 Level 1 (0 points)

            Same problem working with iOS 11, xcode 10.1 and swift 4.2!