Reputation: 3968
I am creating a game. When the game is over I am showing a button "Play again" which, ideally, should just reload the Scene.
var viewSize = currentScene.view?.bounds.size
let sceneG = Level1(size: viewSize!)
currentScene.view?.presentScene(sceneG)
but unfortunately, I am getting this error:
Attemped to add a SKNode which already has a parent:
Because some nodes already exist in the Scene and is not possible to add them again.
Is there a way to reload the scene or removing all nodes before presenting the scene again?
Thank you
As requested, this is the Level1 class:
import SpriteKit
import CoreMotion
class Level1: SKScene {
override func didMoveToView(view: SKView) {
//creation of nodes etc
}
}
Upvotes: 3
Views: 1829