简体   繁体   中英

Loading Screen SpriteKit Swift To Improve Frame Rate

I'm trying to create a "Loading Screen" to preload all the textures.

I have the following in GameViewController.swift :

    class GameViewController: UIViewController {

    var catAtlas = SKTextureAtlas(named:"cat@2x")
    //And many more atlas

    override func viewDidLoad() {
     super.viewDidLoad()

    var textureAtlas = NSMutableArray()

    textureAtlas.addObject(catAtlas)


    SKTextureAtlas.preloadTextureAtlases(textureAtlas, withCompletionHandler: {

           //Present Scene

        }

    })

}

And in a class called Obstacles.swift which is implemented in GameScene.swift:

    class Obstacles {

init() { }


 var catAtlas = SKTextureAtlas(named:"cat@2x")


func catAnimation(){
  //Where catAtlas is used
    }

    }

This way the textures are stored in RAM, but the frame rate does not change (It`s the same without preload). And if I do the following the frame rate worsens:

 var pinataTextAtlas = GameViewController().catAtlas

What am I doing wrong or how I can fix this?

Thank You! (Sorry for my english)

Preloading will only improve the frame rate if you see frame rate drops due to loading textures at runtime. Clearly this isn't the case for you.

Here's some possible things you can do to narrow it down:

  • run on a device (simulator performane is always terrible)
  • reduce number of nodes
  • reduce number of nodes with physics bodies
  • reduce number of physics bodies colliding simultaneously/frequently
  • run Instruments to profile your app

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM