Search code examples
iossprite-kitcollisionskspritenodeskview

How to detect collision between SKSpriteNode and SKView SpriteKit


I have nine SKSpriteNodes that fall down from the top to the bottom of a screen. Also i have SKView, and I can drag it over the screen. How can I detect collision of my SKView with one of the nine SKSpriteNodes dynamically ?


Solution

  • SKView doesn't have physicsBody property, so it cannot collide.

    You can, however, manually check if SKView's frame intersects with SKSpriteNode's frame:

    - (void)update:(CFTimeInterval)currentTime {
        if (CGRectIntersectsRect(skView.frame, node.frame) {
            ....
        }
    }