我有两个空白的scnscene对象,没有任何节点和摄影机:
func setupScenes() {
scnView = SCNView(frame: self.view.frame)
self.view.addSubview(scnView)
gameScene = SCNScene(named: "/MrPig.scnassets/GameScene.scn")
splashScene = SCNScene(named: "/MrPig.scnassets/SplashScene.scn")
scnView.scene = splashScene
}
显示每个scnscene的两种方法:
func startSplash() {
gameScene.isPaused = true
let transition = SKTransition.doorsOpenVertical(withDuration: 1.0)
scnView.present(splashScene, with: transition, incomingPointOfView: nil, completionHandler: {
self.gameState = .tapToPlay
self.setupSounds()
self.splashScene.isPaused = false
})
}
func startGame() {
splashScene.isPaused = true
let transition = SKTransition.doorsOpenVertical(withDuration: 1.0)
scnView.present(gameScene, with: transition, incomingPointOfView: nil, completionHandler: {
self.gameState = .playing
self.setupSounds()
self.gameScene.isPaused = false
})
}
以及用于在scnscenes之间切换的触摸手势:
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
if gameState == .tapToPlay {
startGame()
} else {
startSplash()
}
}
每次我触摸屏幕时,屏幕上都会出现第一个或第二个scnscene,我习惯了加上大约80Mb的RAM。触摸10次后,已使用500MB内存。
我不明白为什么会这样?
发布于 2019-02-21 00:11:40
我遇到了完全相同的问题,找不到原因,但我猜这与spritekit有关,特别是当你同时使用metal和scenekit时。参见scenekit spritekit memory leak。呈现(场景...)来自spritekit。我想出的唯一解决方案是直接设置SCNView的场景和指向视图,而不是通过present(...)方法。
https://stackoverflow.com/questions/54386840
复制相似问题