I have a GameScene.sks, GameScene class and GameViewController. I can create a protocol without using sks but I want to do this using SKScene(fileNamed: "GameScene")
.
When I use scene.gameDelegate = self
in GameViewController, viewDidload()
I'm getting Value of type 'SKScene' has no member gameDelegate
error.
How Can I overcome this problem?
protocol GameDelegate {
func createAds()
}
GameScene class:
class GameScene: SKScene {
var gameDelegate: GameDelegate!
...
GameViewController viewDidLoad:
if let view = self.view as! SKView? {
if let scene = SKScene(fileNamed: "GameScene") {
scene.scaleMode = .aspectFill
scene.gameDelegate = self // Value of type 'SKScene' has no member gameDelegate
gameState = .playing
view.presentScene(scene)
}
view.ignoresSiblingOrder = true
}
Initialize the local variable
scene
as yourGameScene
subclass ofSKScene
. This would look something like:Also ensure that the
GameViewController
class conforms to theGameDelegate
protocol and implements all of the required interface methods.