我对Gamescene
有疑问。游戏结束后,将会出现一个游戏结束场景,该场景允许我单击NewGame Button,但事实是,当我单击它时,Gamescene
会再次出现更大的幅度。
import UIKit
import SpriteKit
class GameOver: SKScene{
var score: Int = 0
//var scoreLabel: SKLabelNode!
var newGameButtonNode: SKSpriteNode!
override func didMove(to view: SKView) {
newGameButtonNode = (self.childNode(withName: "NewGameButton") as! SKSpriteNode)
newGameButtonNode.texture = SKTexture(imageNamed: "NewGame")
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
let touch = touches.first
if let locations = touch?.location(in: self){
let node = self.nodes(at: locations)
if node[0].name == "NewGameButton" {
let gameScene = SKScene(fileNamed: "GameScene")
gameScene!.size = self.size
gameScene!.scaleMode = .aspectFit
let transition = SKTransition.flipHorizontal(withDuration: 1)
view!.presentScene(gameScene!, transition: transition)
}
}
}
}