我正在创建一个游戏,在那里我创建了一个如何玩游戏的教程页面。我只希望教程页面在他们第一次下载应用程序时显示。如果他们已经有应用程序,让他们直接去玩游戏。
这是我的教程代码:
class TutorialPage: SKScene{
let playGameButton = SKLabelNode(fontNamed: "Helvetica")
override func didMove(to view: SKView) {
// How to Play Title
let tutorialLabel = SKLabelNode(fontNamed: "Helvetica")
tutorialLabel.text = "How to Play"
tutorialLabel.fontSize = 30
tutorialLabel.fontColor = SKColor.pink
tutorialLabel.position = CGPoint(x: self.size.width / 2, y: self.size.height * 0.75)
tutorialLabel.zPosition = 1
self.addChild(tutorialLabel)
let movementLabel = SKLabelNode(fontNamed: "Helvetica")
movementLabel.text = "Lorem Ipsum is a dummy text.
movementLabel.fontSize = 15
movementLabel.fontColor = SKColor.blue
movementLabel.position = CGPoint(x: self.size.width / 2, y: self.size.height * 0.65)
movementLabel.zPosition = 1
self.addChild(movementLabel)
// PLay Game Button
playGameButton.text = "Start Playing"
playGameButton.fontSize = 25
playGameButton.fontColor = SKColor.green
playGameButton.position = CGPoint(x: self.size.width / 2, y: self.size.height * 0.2)
playGameButton.zPosition = 1
self.addChild(playGameButton)
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
for touch: AnyObject in touches{
let pointOfTouch = touch.location(in: self)
if playGameButton.contains(pointOfTouch){
let sceneToMoveTo = GameScene(size: self.size)
sceneToMoveTo.scaleMode = self.scaleMode
let myTransition = SKTransition.doorsOpenHorizontal(withDuration: 1)
self.view!.presentScene(sceneToMoveTo, transition: myTransition)
}
}
}
}
答案 0 :(得分:0)
您需要保存像hasShownTutorial这样的变量:Bool = false。表示您是否已将它们显示在教程中,然后在显示教程后将变量保存到NSUserDefaults或pList。在启动时,您将加载该变量,如果它是假的,请向他们展示教程,如果是,则跳过教程。