出现Gameover场景后如何返回GameScene?

时间:2018-10-18 10:45:27

标签: ios swift xcode swift4 skscene

我对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)
            }
        }
    }
}

0 个答案:

没有答案