How many View Controllers should I have in my game?

非 Y 不嫁゛ 提交于 2020-01-04 09:18:33

问题


I'm starting to build my first game using spritekit. Right now I have only one View Controller which presents the start screen scene:

override func viewDidLoad() {
    super.viewDidLoad()

    let scene = StartScreenScene()

    // Configure the view.
    let skView = self.view as SKView
    skView.showsFPS = true

    /* Sprite Kit applies additional optimizations to improve rendering performance */
    skView.ignoresSiblingOrder = true

    /* Set the scale mode to scale to fit the window */
    scene.scaleMode = .AspectFill

    skView.presentScene(scene)
}

After the start screen is loaded it presents the next scene and so on. While this is working for me I'm not sure if it's correct or if it may hurt performance. Should I have a View Controller for each scene? How many View Controllers should I have?


回答1:


Short answer: 1 is fine!

Long answer: It depends on what you want to have in your application! I have a SpriteKit game that has 3 non-modal ViewControllers: The title screen, the level selection, and the main game screen. However, all of my gameplay is contained within one. SKView can very easily manage unloading/loading scenes with presentScene and presentScene:transition:.



来源:https://stackoverflow.com/questions/25577743/how-many-view-controllers-should-i-have-in-my-game

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!