Is it ok to configure (position sprites, add visible nodes etc) an SKScene's content in init method?
Where is the right place for such things: init? didMoveToView? something else?
Is it ok to configure (position sprites, add visible nodes etc) an SKScene's content in init method?
Where is the right place for such things: init? didMoveToView? something else?
didMoveToView: is called every time the scene is presented by an SKView. Pros of positioning and adding sprites in didMoveToView: You can initialise many views without them grabbing a lot of memory. Cons: If you remove a view and then add it again didMoveToView: is called again. This means that you need to be sure to reset your scene in the beginning of didMoveToView: (only if you intend to remove and add again).
init is called when you initialise the SKScene. Pros of using init for positioning and adding sprites: It is only called once, and everything will be ready once you present it on the scene. If you need to preload scenes for quick switching this might be handy. Cons: Each scene will take up the memory it needs to perform all the adding of sprites when init'ed and not when its shown.
Personally, I prefer to do everything in the init method.
© 2022 - 2024 — McMap. All rights reserved.