微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

SwiftUI 应用程序在再次激活后重置 SKScene

如何解决SwiftUI 应用程序在再次激活后重置 SKScene

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

我的代码

print(search("hiXherehello","*he*e")) # True
print(search("hitherXhello","the*e")) # False

更新

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()
                ....

解决方法

尝试设置场景的大小和缩放模式inside 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()
                ....

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。