Почему мои сцены SKS увеличиваются при каждом переходе? - PullRequest
0 голосов
/ 01 февраля 2020

У меня есть несколько SKS-сцен со спрайтами, которые действуют как кнопки и переходят на другую сцену и наоборот. Всякий раз, когда я go перехожу на новую сцену, нажимая спрайт с переходом DoorsCloseHorisontal, а затем go возвращает исходную сцену с помощью другого спрайта, страница каждый раз слегка увеличивается. Вот код, который я использую для первой сцены (StartScene).

import SpriteKit
import GameplayKit

class StartScene: SKScene {


    override func didMove(to view: SKView) {

    }

    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {

         for touch in touches {
                    if touch == touches.first {
                        print("start")


                        enumerateChildNodes(withName: "startButton", using: { (SKNode, stop) in
                            if SKNode.name == "startButton" {
                                if SKNode.contains(touch.location(in: self)) {
                                    let gameSceneTemp = StartScene(fileNamed: "levelSelectScene")
                                    self.scene?.view?.presentScene((gameSceneTemp ?? nil)!, transition: SKTransition.doorsCloseHorizontal(withDuration: 1.0))
                                }
                        }
                    })

                  enumerateChildNodes(withName: "shopButton", using: { (SKNode, stop) in
                                           if SKNode.name == "shopButton" {
                                               if SKNode.contains(touch.location(in: self)) {
                                                   let gameSceneTemp = StartScene(fileNamed: "shopScene")
                                                   self.scene?.view?.presentScene((gameSceneTemp ?? nil)!, transition: SKTransition.doorsCloseHorizontal(withDuration: 1.0))
                                               }
                                       }
                                   })
                    enumerateChildNodes(withName: "optionsButton", using: { (SKNode, stop) in
                                                            if SKNode.name == "optionsButton" {
                                                                if SKNode.contains(touch.location(in: self)) {
                                                                    let gameSceneTemp = StartScene(fileNamed: "optionsScene")
                                                                    self.scene?.view?.presentScene((gameSceneTemp ?? nil)!, transition: SKTransition.doorsCloseHorizontal(withDuration: 1.0))
                                                                }
                                                        }
                                                    })
            }
                }
            }


    override func update(_ currentTime: TimeInterval) {
        // Called before each frame is rendered
    }

}

А вот вторая сцена (optionsScene)

import SpriteKit
import GameplayKit

class OptionsScene: SKScene {


    override func didMove(to view: SKView) {

    }

    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {

         for touch in touches {
                    if touch == touches.first {
                        print("start")


                        enumerateChildNodes(withName: "optionsBack", using: { (SKNode, stop) in
                            if SKNode.name == "optionsBack" {
                                if SKNode.contains(touch.location(in: self)) {
                                    let gameSceneTemp = StartScene(fileNamed: "startScene")
                                    self.scene?.view?.presentScene((gameSceneTemp ?? nil)!, transition: SKTransition.doorsCloseHorizontal(withDuration: 1.0))
                                }
                        }
                    })

            }
                }
            }


    override func update(_ currentTime: TimeInterval) {
        // Called before each frame is rendered
    }

}

Итак, когда я go возвращаюсь для начала сцены сцена немного увеличивается

...