0

每次我的应用程序进入后台然后再次激活时,SpriteView 总是会重置,并且 SKScene 会回到关卡的开头。我怎样才能阻止这种情况或我做错了什么?

我的代码:

struct GameContainer: View {

    private var scene: SKScene {
        let scene = Splash()
        scene.size = Size.shared.setupSceneSize()
        scene.scaleMode = .aspectFit
        return scene
    }  

    var body: some View {
        SpriteView(scene: scene, options: .ignoresSiblingOrder)
            .edgesIgnoringSafeArea(.all)
            .statusBar(hidden: true)
    }
}

struct Game: View {

    ...

    var body: some View {
        NavigationView {
            ZStack {
                GameContainer()
                ....

更新

struct GameContainer: View {

    static var scene = Splash()

    var body: some View {
        SpriteView(scene: GameContainer.scene, options: .ignoresSiblingOrder)
            .edgesIgnoringSafeArea(.all)
            .statusBar(hidden: true)
    }
}

class Splash: SKScene {
     override init() {
         super.init(size: Size.shared.setupSceneSize())
         scaleMode = .aspectFit
     }
     ....
}
4

1 回答 1

0

尝试在里面 设置场景的大小和缩放模式Splash(),然后设为scene静态。我认为这应该可以解决 SpriteView 一直重新加载的问题。

struct GameContainer: View {

    static var scene = Splash()

    var body: some View {
        SpriteView(scene: GameContainer.scene, options: .ignoresSiblingOrder)
            .ignoresSafeArea()
            .statusBar(hidden: true)
    }
}

struct Game: View {

    ...

    var body: some View {
        NavigationView {
            ZStack {
                GameContainer()
                ....
于 2021-05-04T19:51:42.647 回答