Reputation: 293
I am having an issue with my SpriteKit Scene File. I currently have my GameScene.sks lined to my GameScene.swift file. When my app loads up the user enters a menu, then the user presses play and is transitioned to the GameScene file to play the game via:
let gameScene = SKScene(fileNamed: "GameScene")
gameScene?.scaleMode = .aspectFit
self.view?.presentScene(gameScene!, transition: SKTransition.fade(withDuration: 1.5))
When the player hits an object in the game they die and go back to the menu (also linked to a .sks file) :
let menu = SKScene(fileNamed: "menu")
menu?.scaleMode = .aspectFill
self.view?.presentScene(menu!, transition: transition)
Here where my issue is, after the user is brought back to the menu, the next time they hit play the user immediately dies and is brought back to the menu.
This is because when GameScene is called everything is the same as when the user died. In other words, the player is contacting the same node that caused them to die.
Is there any way to reset the GameScene? I have tried removing all nodes to no avail.
Am I presenting the scenes wrong?
Upvotes: 0
Views: 73
Reputation: 293
I Figured it out! I moved my removeFromParent() statement into my menu.swift file. Right before I'm about to transition to GameScene:
obstacles.removeFromParent()
then
let gameScene = SKScene(fileNamed: "GameScene")
gameScene?.scaleMode = .aspectFit
self.view?.presentScene(gameScene!, transition: SKTransition.fade(withDuration: 1.5))
Please let me know if you have a better solution. Thanks!
Upvotes: 2