Where is the right place to configure SKScene content in SpriteKit?

Is it possible to customize (place sprites, add visible nodes, etc.) the contents of SKScene in the init method?

Where is the right place for things like this: init? didMoveToView? something else?

+4
objective-c sprite-kit skscene
source share
1 answer

didMoveToView: called every time a scene is presented by SKView. Pros of positioning and adding sprites in didMoveToView: you can initialize many views without capturing a lot of memory. Cons: If you delete the view and then add it again, then makeMoveToView: called again. This means that you need to be sure to reset your scene at the beginning of didMoveToView: (only if you intend to delete and add again).

init is called when SKScene is initialized. Advantages of using init to position and add sprites: it is called only once, and everything will be ready when you present it on stage. If you need to preload scenes for quick switching, this can be convenient. Cons: each scene will take up the memory needed to perform all sprite additions during initialization, and not when it is displayed.

Personally, I prefer to do everything in the init method.

+8
source share

All Articles