Search code examples
swift3collision-detectionskspritenode

Check for collisions between SKSprite nodes that don't have physics bodies


I have two SkSprite nodes.

var player = SKSpriteNode()
var colorWheel = SKSpriteNode()

Is there a simple way for me to detect collisions between them without having to give them physics bodies. Thanks for the help.


Solution

  • There is a way of doing this using the update() method

    override func update(_ currentTime: TimeInterval) {
    
        if player.frame.intersects(colorWheel.frame) {
            //Nodes are colliding
        }
    }
    

    This is just a starting point and will be triggered for each frame where the nodes are colliding. You will have to write down additional logic to handle one-off collisions etc.