I keep getting an error the player node is always nil I cannot figure this out for the life of me.
Is anyone else getting this error ?? But when I put addchild(player) instead it has both characters on the scene…very confused.
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
background = childNode(withName: "background layer") as! SKTileMapNode
obstaclesTileMap = childNode(withName: "obstacles") as? SKTileMapNode
if let timeLimit = userData?.object(forKey: "timeLimit") as? Int {
self.timeLimit = timeLimit
}
let savedGameState = aDecoder.decodeInteger(forKey: "Scene.gameState")
if let gameState = GameState(rawValue: savedGameState), gameState == .pause {
self.gameState = gameState
firebugCount = aDecoder.decodeInteger(forKey: "Scene.firebugCount")
elapsedTime = aDecoder.decodeInteger(forKey: "Scene.elapsedTime")
currentLevel = aDecoder.decodeInteger(forKey: "Scene.currentLevel")
player = childNode(withName: "Player") as! Player
hud = camera!.childNode(withName: "HUD") as! HUD
bugsNode = childNode(withName: "Bugs")!
bugsprayTileMap = childNode(withName: "Bugspray") as? SKTileMapNode
}
addObservers()
}