I created a main menu scene view after GameScene is done. GameScene worked fine by itself. However it doesn't show up in the center after it's transferred from the main menu scene view. Both sks files have the same width and height dimensions and anchor points. Why is that?
class Menu: SKScene {
var newGameButtonNode: SKSpriteNode?
var bossFightButtonNode: SKSpriteNode?
var highScoreLabelNode: SKLabelNode?
override func didMove(to view: SKView) {
newGameButtonNode = self.childNode(withName: "newGameButton") as? SKSpriteNode
bossFightButtonNode = self.childNode(withName: "bossFightButton") as? SKSpriteNode
highScoreLabelNode = self.childNode(withName: "highScoreLabel") as? SKLabelNode
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
//set touch to self
let touch = touches.first
if let location = touch?.location(in: self) {
let nodesArray = self.nodes(at: location)
if nodesArray.first?.name == "newGameButton" {
let transition = SKTransition.flipHorizontal(withDuration: 0.5)
let gameScene = GameScene(size: self.size)
gameScene.scaleMode = .aspectFill
self.view?.presentScene(gameScene, transition: transition)
}
}
}
}
If you have a corresponding SKS file created in the Scene editor then you load your scene like so...
if you do not have a corresponding SKS file created in the scene editor but would rather load the scene that was created in code use...
You say that both have corresponding SKS files yet you are attempting to load it via the code init from the scene