GameScene 完成后,我创建了一个主菜单场景视图。GameScene 本身运行良好。但是,从主菜单场景视图传输后,它不会显示在中心。两个 sks 文件具有相同的宽度和高度尺寸以及锚点。这是为什么?
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)
}
}
}
}