Frame drop when presenting a new scene in SpriteKit

27 Views Asked by At

The architecture of my game is simple: a GameViewController which loads and presents a GameScene and a MenuScene alternatively on user interaction.

private func startNewGame(textures: [SKTexture]? = nil) {
    let gameScene = GameScene(size: view.frame.size, textures: gameTextures)
    gameScene.scaleMode = .aspectFill
    gameScene.gameSceneDelegate = self
    show(gameScene)
}

private func showMenuScene(textures: [SKTexture]? = nil) {
    let menuScene = MenuScene(size: view.frame.size, textures: textures)
    menuScene.menuSceneDelegate = self
    show(menuScene)
}    

private func show(_ scene: SKScene, scaleMode: SKSceneScaleMode = .aspectFill) {
    guard let skView = view as? SKView else {
        preconditionFailure()
    }
    scene.scaleMode = .aspectFill
    skView.presentScene(scene, transition: SKTransition.fade(withDuration: 1))
}

The issue I'm facing is that, whenever there is a transition between scenes, I experience a frame drop to about 45/50 fps for about 3-4 seconds. After that, in both scenes I can achieve 60 fps consistently.

I'm performing some animations on both scenes on presentation in didMove(to view: SKView) and of course some of those are laggy due to the frame drop. All animations are simple, such as translations, rotations, or moving the player on joystick input. I got 12 nodes in MenuScene and around 17-20 nodes in GameScene.

I assumed this is normal since all the scene nodes were just instantiated in sceneDidLoad(), but is it really? If not, is there any way I can reduce the frame drop, stated that cutting down the number of nodes is not an option?

I was already able to cut down the frame drop by a bit by preloading and storing textures in GameViewController and then passing them to the scene on creation, but the issue stands still.

0

There are 0 best solutions below