I have made a game where the basics is, if a sprite node collides with a wall i looses and if it collides with a separate node(Ball2) you will you win. I have made how to detect the collision which makes you lose the game but not when the Ball collides with ball2. So my question is how to make two different collisions which makes different things happen? I would really love some help, thanks
struct PhysicsCategogy {
static let Ball : UInt32 = 0x1 << 1
static let Ball2 : UInt32 = 0x1 << 1
static let WallH : UInt32 = 0x1 << 2
static let WallH2 : UInt32 = 0x1 << 3
}
class GameScene: SKScene, SKPhysicsContactDelegate {
var Ball = SKSpriteNode(imageNamed: "Ball")
var Ball2 = SKSpriteNode(imageNamed: "Ball")
var WallH = SKSpriteNode(imageNamed: "WallH")
override func didMoveToView(view: SKView) {
self.view?.paused = false
self.physicsWorld.gravity = CGVector(dx: 0, dy: 0)
self.physicsWorld.contactDelegate = self
Ball.position = CGPointMake(self.frame.width / 2 - 450, self.frame.height / 2)
Ball.setScale(0.5)
Ball.physicsBody = SKPhysicsBody(rectangleOfSize: Ball.size)
Ball.physicsBody?.affectedByGravity = false
Ball.physicsBody?.dynamic = true
Ball.physicsBody?.contactTestBitMask = PhysicsCategogy.Ball
Ball.physicsBody?.collisionBitMask = 0
Ball.physicsBody?.collisionBitMask = 2
addChild(Ball)
Ball2.position = CGPointMake(self.frame.width / 2 + 450, self.frame.height / 2)
Ball2.setScale(0.5)
Ball2.physicsBody = SKPhysicsBody(rectangleOfSize: Ball.size)
Ball2.physicsBody?.affectedByGravity = false
Ball2.physicsBody?.dynamic = true
Ball2.physicsBody?.contactTestBitMask = PhysicsCategogy.Ball2
Ball2.physicsBody?.collisionBitMask = 1
addChild(Ball2)
WallH.position = CGPointMake(self.frame.width / 2, self.frame.height / 2 + 190)
WallH.setScale(7.5)
WallH.physicsBody = SKPhysicsBody(rectangleOfSize: WallH.size)
WallH.physicsBody?.affectedByGravity = false
WallH.physicsBody?.contactTestBitMask = PhysicsCategogy.WallH
WallH.physicsBody?.collisionBitMask = 0
self.addChild(WallH)
}
func didBeginContact(contact: SKPhysicsContact) {
self.backgroundColor = SKColor.whiteColor()
self.view?.paused = true
}
}