每次我的应用程序进入后台然后再次激活时,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
}
....
}