1
votes

When i click the playButton from my MenuScene to change to the GameScene it works fine. Only every node, sprite,... changes from position in my GameScene. It's like the anchorpoint changes form (0,5 ; 0,5) to (0,0). I don't know where or what to change. In my .sks files both anchor points in the attributes inspector are the same.

This is the code where i change from the MenuScene to the GameScene: This is written in the MenuScene:

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {

  let touch = touches.first

    if let location = touch?.location(in: self) {
        let nodeArray = self.nodes(at: location)

        if nodeArray.first?.name == "playButton" {
            let transition = SKTransition.fade(withDuration: 0.5)
            let gameScene = GameScene(size: self.size)
            gameScene.scaleMode = SKSceneScaleMode.aspectFill
            self.view?.presentScene(gameScene, transition: transition)
        }
    }
}

Thanks in advance!!

1

1 Answers

1
votes

This line GameScene(size: self.size) means you are creating a default GameScene object at the size of the previous scene. Avoid using this initializer at almost all cost. Instead doGameScene(fileNamed:"GameScene") and set your scaleMode from the old scene to this one