0

I have 3 view controllers, HomeVC, GameStartVC, GameOverVC. The GameStartVC has a view frame inside its view which has the sprite kit game that works perfectly, but when there's a game over and it goes to the GameOverVC and then I tap the play again button which goes back to the GameStartVC, or even transition to the HomeVC and then play again after a couple of times there's a huge lag.

The play and play again are buttons linked to the GameStartVC from the HomeVC and the GameOverVC, respectively, via the storyboard. Going back to HomeVC from the GameOverVC is also from the storyboard. Going from the GameStartVC to the GameOverVC is done via code.

The deinit{} doesn't help. It gets called but the lag is still there.

GameStartVC file

@IBOutlet weak var selfView: SKView!
@IBOutlet weak var scoreLabel: UILabel!
@IBOutlet weak var bottomConstraint: NSLayoutConstraint!

var scene: GameScene!
var skView: SKView!
var adMobBanner: GADBannerView!

override func viewDidLoad() {
    super.viewDidLoad()

    self.view.backgroundColor = UIColor.feelFreeToColor()
    self.initAdMobBanner()
    scene = GameScene(size: self.view.bounds.size)
    scene.gs = self

    skView = selfView
    skView.showsFPS = false
    skView.showsNodeCount = false
    skView.ignoresSiblingOrder = true
    scene.scaleMode = .AspectFill
    skView.presentScene(scene)

    score = 0
    scoreLabel.text = "\(score)"
    scoreLabel.layer.addBorder(UIRectEdge.Bottom, color: UIColor.blackColor(), thickness: 3)
}

deinit {
    print("GONE")
}

GameScene file (inside the touchesBegan() where the transition happens)

          else {

                self.playSound(Config.wrongSoundFileName)
                if score > highScore {
                    highScore = score
                    NSUserDefaults.standardUserDefaults().setInteger(highScore, forKey: "HighScore")
                }


                let goVC = self.gs.storyboard?.instantiateViewControllerWithIdentifier("GameOverViewController") as! GameOverViewController
                goVC.modalTransitionStyle = UIModalTransitionStyle.CrossDissolve
                self.gs.presentViewController(goVC, animated: true, completion: {
                    self.removeAllChildren()
                    self.removeAllActions()
                    self.scene?.removeFromParent()
                    print("GONE")
                })

            }
  • Not an answer to your question but consider using one view controller like this : http://stackoverflow.com/a/35409586/3402095. That is the way how SpriteKit games are usually organized. – Whirlwind May 12 '16 at 08:17
  • I've done it that way before. But I have the views set up the way it does in design. I found it easier it make the design via story word than SpriteKit. I just wouldn't work if I did it in Sprite kit – Mohamed Mohamed May 12 '16 at 08:39

0 Answers0