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")
})
}