2

I have two SKScenes which I transition in between as follows:

self.skView.presentScene(scene, transition: SKTransition.fadeWithDuration(1.0))

As soon as scene-1 is faded out (after 0.5s) and the screen is black, I would like to execute some code (re-assign camera node, etc.), so that everything is properly setup after the second 0.5s when fading in.

Is there any callback function ready to use for this in-between-event ?

salocinx
  • 3,715
  • 8
  • 61
  • 110
  • 1
    The best you can do is override the `didMoveFromView`, of your old scene, and fire an `NSNotification` when it happens (You can't use `didMoveToView` in the new scene because this applies instantly when transitioning) – Knight0fDragon Sep 12 '16 at 14:53
  • 1
    I do not get why you need to do this during the .00001 second of a fade, why not just set up everything before you transition. – Knight0fDragon Sep 12 '16 at 14:54
  • 1
    @salocinx It's a bad idea if you want to do somethings that run to the main thread, better to do these things before you transition.. – Alessandro Ornano Sep 12 '16 at 15:05
  • Thanks for your comments. The background is, that I have a "starfield parallax background" with 200 sprites. This moving background is attached to the camera. This is the reason why I have only one camera for multiple scenes, so that I don't need to have multiple starfields. But maybe it's better to have one camera instance for each scene and therefore also multiple starfields. What do you think? – salocinx Sep 12 '16 at 16:02
  • 1
    @salocinx A starfield parallax background is one of the simplest parallax bg you can realize, I think you could realize it with SKEmitterNode.. – Alessandro Ornano Sep 12 '16 at 16:44
  • @Alessandro Ornano: My starfield background is already working great! But the issue I am confronted, is more about changing scenes and how to pass the starfield sprites to the next scene. But I now try the approach of instantiating the starfield for each scene separately rather then passing it from scene to scene. I let you know if it works for me. Thanks so far for your help! – salocinx Sep 12 '16 at 16:50
  • 1
    @salocinx :-| If you change the scene, your device should remove from memory the scene so you can start with another scene, where is the problem? Here you don't have to do with a table that scroll and you can reuse cells to don't overload the memory, here you pass from a scene to another scene. – Alessandro Ornano Sep 12 '16 at 16:53
  • 1
    @salocinx, just copy the camera into the new scene, do not move it, When the old scene is removed, the camera memory will die with it. – Knight0fDragon Sep 12 '16 at 17:02
  • thank you very much. I refactored the game as you guys suggested and it meanwhile looks much better. the menu scene gets properly deallocated, but the game scene does not. probably there's somewhere a retain cycle left, but I already defined all reference objects that I pass to other classes (and keep reference in there) as "weak" in order to avoid retain cycles. but the game scene is not deallocated. is there any efficient trick to find out why the scene is not deallocated properly? – salocinx Sep 12 '16 at 20:48
  • 1
    You need to find everywhere that your object could be retained, not just blocks. Somethings do not give you the option of passing a weak ref, like NSTimer – Knight0fDragon Sep 13 '16 at 03:48
  • 1
    @salocinx There are several way to avoid retain cycles, try to report your code here in an update section or to another question, I will gladly give you a hand to solve the problem. – Alessandro Ornano Sep 13 '16 at 07:18
  • Yeah - finally I got it. I had a block where "self" was neither as "unowned" nor as "weak" defined. This block was a bit different from the blocks I searched for. Now everything gets deallocated properly. Thank you both so much for your help!! – salocinx Sep 13 '16 at 13:34

0 Answers0