How to call method from ViewController in GameScene

the reason this doesnt work is that you are creating a NEW instance of GameViewController and then you’re calling gameOver on that. What you really want to do is reference your existing GameViewController

theres a few ways to do this, I’ll give you one example.

add a viewController property to your GameScene class

class GameScene {

    // we need to make sure to set this when we create our GameScene
    var viewController: GameViewController!

in your GameViewController file

// after GameScene is instantiated
gameScene.viewController = self

now we have a reference to viewController, lets use it in our GameScene class

// somewhere in GameScene
self.viewController.gameOver()

Leave a Comment