kriskendall99
kriskendall99

Reputation: 547

Stop Sprites from Pushing Each Other in SpriteKit

I'm coding a SpriteKit game and I'm trying to add the equivalent of a Cocos2D sensor. My problem is that my sensor keeps pushing the other sprites, but this isn't what I want. I want the sensor to be able to overlap with other sprites and not push them around. How do I fix this? Here is the code I've added for my sensor:

bubble.physicsBody = SKPhysicsBody(circleOfRadius: CGFloat(50))
bubble.physicsBody?.dynamic = false
bubble.physicsBody?.allowsRotation = false
bubble.physicsBody?.affectedByGravity = false

And here is my collision method:

func didBeginContact(contact: SKPhysicsContact) {
    let collision:UInt32 = (contact.bodyA.categoryBitMask | contact.bodyB.categoryBitMask)

    if collision == (playerCategory | crateCategory) {
        NSLog("Game Over")
        var myLabel = SKLabelNode(fontNamed: "Arial")
        myLabel.text = "GAME OVER"
        myLabel.fontSize = 50
        myLabel.color = SKColor.blueColor()
        myLabel.position = (CGPointMake(self.frame.size.width*0.5, self.frame.size.height*0.5))
        self.addChild(myLabel)
        fisherman.physicsBody?.dynamic = false
        fisherman.removeFromParent()
        fish.physicsBody?.dynamic = false
        fish.removeFromParent()
        crate.physicsBody?.dynamic = false
        crate.removeFromParent()
        crateDuplicate.physicsBody?.dynamic = false
        crateDuplicate.removeFromParent()


    }
    if collision == (playerCategory | bubbleCategory) {
        NSLog("Bubble Contact")
        bubbleDuplicate.removeAllActions()
        bubbleDuplicate.removeFromParent()
        bubble.removeAllActions()
        bubble.removeFromParent()
        bubbleDuplicate.setScale(0)
        bubble.setScale(0)
        bubbleDuplicate.alpha = 0


               }


}

Upvotes: 1

Views: 482

Answers (1)

Nikita Leonov
Nikita Leonov

Reputation: 5694

Set a collisionBitMask to 0, so all collisions of this particular object to others will be ignored.

Upvotes: 3

Related Questions