Chapter 14 - Loading a game mess up collision detection

I’m almost finished with the chapter but I noticed that after loading a saved game, the collision detection between Arnie and the bugs doesn’t work anymore. The bugs simply bounce away and do not disappear.

I have tried the provided “final” project as well, and it actually shows the same behavior. So either there is a bug(!) still in the code, or the problem is the fact that I’m running Xcode 11.5. I did not upgrade the code to Swift 5 when prompted though.

Any clues? :slight_smile:

Regards,
Andreas

PS. Thanks for an awesome book!!!

If that bug has lasted this long without detection, I am amazed! But it seems that it is so. Congratulations :clap:!

What’s happening is that on reload, the physics delegate isn’t being set, so didBegin(_:) in SKPhysicsDelegate isn’t being performed.

In didMove(to:), move the line setupWorldPhysics() out of the conditional and to the end of the method. It should now work.

P.S. I’m really glad you’re enjoying the book :relaxed: - I wonder what WWDC will bring us.

Thanks a lot for your help, that makes a lot of sense! Yes, I was almost certain I had missed something, so I was really surprised to find it also in the “final” project. :slight_smile:

1 Like

This topic was automatically closed after 166 days. New replies are no longer allowed.