Search code examples
sprite-kitremovechildskspritenodesknode

Sprite Kit Remove SKNode From Parent When Off Screen


I would like to know how to remove my SKNodes when they are off screen to help my game run more smoothly.

How To Do This On Sprite Kit

Thanks So Much


Solution

  • https://stackoverflow.com/a/24195006/2494064

    Here is a link to an answer that removes nodes that go off the top of the screen. You would just have to replicate this to cover the entire border and set all of the walls to have the same contactBitMask values.

    Basically the logic is to remove the SKSpriteNodes when they contact physicsbodies that you have resting just outside the visible screen.