I have a problem with my func contact because the second contact don't work (contact with Bonus and Vaisseau) but the two others contact don't work.
So this is my code :
The function :
func didBeginContact(contact: SKPhysicsContact) {
let PremierBody : SKPhysicsBody = contact.bodyA
let SecondBody : SKPhysicsBody = contact.bodyB
if ((PremierBody.categoryBitMask == PhysicsCategories.Meteorites) && (SecondBody.categoryBitMask == PhysicsCategories.Meteorites)) {
contactEntreMeteorites(PremierBody.node as! SKSpriteNode, Meteorites2: SecondBody.node as! SKSpriteNode)
}
else if ((PremierBody.categoryBitMask == PhysicsCategories.Bonus) && (SecondBody.categoryBitMask == PhysicsCategories.Vaisseau) ||
(PremierBody.categoryBitMask == PhysicsCategories.Vaisseau) && (SecondBody.categoryBitMask == PhysicsCategories.Bonus)){
gameOver(PremierBody.node as! SKSpriteNode, Vaisseau: SecondBody.node as! SKSpriteNode)
print("CONTACT")
}
else if ((PremierBody.categoryBitMask == PhysicsCategories.Meteorites) && (SecondBody.categoryBitMask == PhysicsCategories.Vaisseau) ||
(PremierBody.categoryBitMask == PhysicsCategories.Vaisseau) && (SecondBody.categoryBitMask == PhysicsCategories.Meteorites)){
gameOver(PremierBody.node as! SKSpriteNode, Vaisseau: SecondBody.node as! SKSpriteNode)
print("Couco")
}
}
And this is my Physics categories :
struct PhysicsCategories {
static let Meteorites : UInt32 = 1
static let Bonus : UInt32 = 2
static let Vaisseau : UInt32 = 5
}
This in my func DidMoveToView :
Vaisseau = SKSpriteNode(texture: Vaisseau1)
Vaisseau.position = CGPointMake(self.frame.size.width / 2, self.frame.size.height / 2)
Vaisseau.physicsBody = SKPhysicsBody(rectangleOfSize: Vaisseau.size)
Vaisseau.physicsBody?.affectedByGravity = false
Vaisseau.physicsBody?.categoryBitMask = PhysicsCategories.Vaisseau
Vaisseau.physicsBody?.contactTestBitMask = PhysicsCategories.Bonus
Vaisseau.physicsBody?.contactTestBitMask = PhysicsCategories.Meteorites
Vaisseau.physicsBody?.dynamic = false
Vaisseau.setScale(0.08)
self.addChild(Vaisseau)
And i create my SpriteNode Bonus in this function :
func ApparitionBonus() {
let BonusSprite = SKSpriteNode(imageNamed: "Bonus.png")
var BonusApparitionX = UInt32(self.frame.size.width)
var BonusApparitionY = UInt32(self.frame.size.height)
BonusApparitionX = arc4random() % BonusApparitionX
BonusApparitionY = arc4random() % BonusApparitionY
BonusSprite.position = CGPointMake(CGFloat(BonusApparitionX),CGFloat(BonusApparitionY))
BonusSprite.setScale(0.8)
BonusSprite.physicsBody = SKPhysicsBody(circleOfRadius: 20)
BonusSprite.physicsBody?.affectedByGravity = false
BonusSprite.physicsBody?.categoryBitMask = PhysicsCategories.Bonus
BonusSprite.physicsBody?.contactTestBitMask = PhysicsCategories.Vaisseau
BonusSprite.physicsBody?.dynamic = false
self.addChild(BonusSprite)
let RotationBonus = SKAction.rotateByAngle(CGFloat(M_PI), duration: 3)
let wait = SKAction.waitForDuration(3)
let actionFini = SKAction.removeFromParent()
BonusSprite.runAction(SKAction.sequence([RotationBonus, wait, actionFini]))
BonusSprite.runAction(SKAction.repeatActionForever(RotationBonus))
}
In your didMoveToView, when you call:
Vaisseau.physicsBody?.contactTestBitMask = PhysicsCategories.Bonus
Vaisseau.physicsBody?.contactTestBitMask = PhysicsCategories.Meteorites
You set the contactTestBitMask to one category, and then another. You need to bitwise or them together. Something like:
Vaisseau.physicsBody?.contactTestBitMask = PhysicsCategories.Bonus | PhysicsCategories.Meteorites
This will combine the two bit masks, which will allow it to contact both the Bonus and Meteorites.
If you don't want your sprites to collide, set the collisionBitMask to 0x0 (or however you want to represent 0):
Vaisseau.physicsBody?.collisionBitMask = 0x0
Related
I have 4 physics bodies that are all detecting collisions well. However, there is two physics bodies that will not detect when they collide with each other. They do detect when they collide with other physics bodies though. I have contacttestbitmasks for all the them so I do not understand why there is a problem. Here is some code:
Here is where I setup my physics bodies:
struct PhysicsCategory{
static let None : UInt32 = 0
static let All : UInt32 = UInt32.max
static let player : UInt32 = 0b1
static let bounce : UInt32 = 0b10
static let blueball : UInt32 = 0b100
static let redball : UInt32 = 0b1000
static let coin : UInt32 = 0b10000
}
Here is the code where I used for setting up the player physics body which is one of the problem physic bodies:
player.physicsBody = SKPhysicsBody(rectangleOf: CGSize(width: player.size.width-40, height: player.size.height-40))
player.physicsBody?.isDynamic = true
player.physicsBody?.categoryBitMask = PhysicsCategory.player
player.physicsBody?.contactTestBitMask = PhysicsCategory.blueball
player.physicsBody?.contactTestBitMask = PhysicsCategory.redball
player.physicsBody?.collisionBitMask = PhysicsCategory.None
Here is the func for detecting collisions:
func didBegin(_ contact: SKPhysicsContact) {
var firstBody: SKPhysicsBody
var secondBody: SKPhysicsBody
if contact.bodyA.categoryBitMask < contact.bodyB.categoryBitMask {
firstBody = contact.bodyA
secondBody = contact.bodyB
} else {
firstBody = contact.bodyB
secondBody = contact.bodyA
}
if ((firstBody.categoryBitMask & PhysicsCategory.player != 0) &&
(secondBody.categoryBitMask & PhysicsCategory.redball != 0)) {
RedballDidCollideWithPlayer(player: firstBody.node as! SKSpriteNode, redball: secondBody.node as! SKSpriteNode)
}
if ((firstBody.categoryBitMask & PhysicsCategory.player != 0) &&
(secondBody.categoryBitMask & PhysicsCategory.blueball != 0)) {
BlueballDidCollideWithPlayer(player: firstBody.node as! SKSpriteNode, blueball: secondBody.node as! SKSpriteNode)
}
if ((firstBody.categoryBitMask & PhysicsCategory.bounce != 0) &&
(secondBody.categoryBitMask & PhysicsCategory.redball != 0)){
RedballDidCollideWithBounce(bounce: firstBody.node as! SKSpriteNode, redball: secondBody.node as! SKSpriteNode)
}
if ((firstBody.categoryBitMask & PhysicsCategory.bounce != 0) &&
(secondBody.categoryBitMask & PhysicsCategory.blueball != 0)) {
BlueballDidCollideWithBounce(bounce: firstBody.node as! SKSpriteNode, blueball: secondBody.node as! SKSpriteNode)
}
if ((firstBody.categoryBitMask & PhysicsCategory.bounce != 0) &&
(secondBody.categoryBitMask & PhysicsCategory.coin != 0)) {
coinDidCollideWithplayer(player: firstBody.node as! SKSpriteNode, coin: secondBody.node as! SKSpriteNode)
}
if ((firstBody.categoryBitMask & PhysicsCategory.player != 0) &&
(secondBody.categoryBitMask & PhysicsCategory.coin != 0)) {
coinDidCollideWithplayer(player: firstBody.node as! SKSpriteNode, coin: secondBody.node as! SKSpriteNode)
}
}
Here is the code I used for setting up the blueball. This is the other physics body having problems:
let blueball = SKSpriteNode(imageNamed: "blueball")
blueball.position = enemyb.position
blueball.physicsBody = SKPhysicsBody(circleOfRadius: blueball.size.width/2)
blueball.physicsBody?.isDynamic = true
blueball.physicsBody?.categoryBitMask = PhysicsCategory.blueball
blueball.physicsBody?.contactTestBitMask = PhysicsCategory.player
blueball.physicsBody?.contactTestBitMask = PhysicsCategory.bounce
blueball.physicsBody?.collisionBitMask = PhysicsCategory.None
blueball.physicsBody?.usesPreciseCollisionDetection = true
addChild(blueball)
let actionMove = SKAction.move(to: player.position, duration: 2)
Any ideas here would be helpful. I have been trying to find the problem for a few days with no luck.
When setting multiple categories you have to OR the values together. Your code
player.physicsBody?.contactTestBitMask = PhysicsCategory.blueball
player.physicsBody?.contactTestBitMask = PhysicsCategory.redball
Just sets the category twice, the second one overwriting the first. Change this to:
player.physicsBody?.contactTestBitMask = PhysicsCategory.blueball | PhysicsCategory.redball
When I run this code the first CollisionWithplayer line gives me a bad instruction error. The error doesn't appear every time, only every once in a while with no similar conditions to identify what is causing it.
func didBeginContact(contact: SKPhysicsContact) {
let firstBody : SKPhysicsBody = contact.bodyA
let secondBody : SKPhysicsBody = contact.bodyB
if ((firstBody.categoryBitMask == PhysicsCategory.Goblin) && (secondBody.categoryBitMask == PhysicsCategory.Bullet) ||
(firstBody.categoryBitMask == PhysicsCategory.Bullet) && (secondBody.categoryBitMask == PhysicsCategory.Goblin))
{
CollisionWithBullet(firstBody.node as! SKSpriteNode, Bullet: secondBody.node as! SKSpriteNode)
}
else if ((firstBody.categoryBitMask == PhysicsCategory.Goblin) && (secondBody.categoryBitMask == PhysicsCategory.player) ||
(firstBody.categoryBitMask == PhysicsCategory.player) && (secondBody.categoryBitMask == PhysicsCategory.Goblin)){
CollisionWithplayer(firstBody.node as! SKSpriteNode, player: secondBody.node as! SKSpriteNode)
}
func CollisionWithBullet(Goblin: SKSpriteNode, Bullet:SKSpriteNode){
Goblin.removeFromParent()
Bullet.removeFromParent()
score += 1
ScoreLbl.text = "\(score)"
var explosion = SKEmitterNode(fileNamed: "Goblin Death Animation.sks")
explosion!.particlePosition = Goblin.position
self.addChild(explosion!)
var fire = SKEmitterNode(fileNamed: "Goblin Death Animation 2.sks")
fire!.particlePosition = Goblin.position
self.addChild(fire!)
}
func CollisionWithplayer(Goblin: SKSpriteNode, player: SKSpriteNode){
let ScoreDefault = NSUserDefaults.standardUserDefaults()
ScoreDefault.setValue(score, forKey: "Score")
ScoreDefault.synchronize()
if (score > Highscore){
let HighscoreDefault = NSUserDefaults.standardUserDefaults()
HighscoreDefault.setValue(score, forKey: "Highscore")
}
Goblin.removeFromParent()
player.removeFromParent()
self.view?.presentScene(EndScene())
ScoreLbl.removeFromSuperview()
}
I assume you get an error because your code doesn't treat the case where 1 collision causes the didBeginContact method to fire more than once (collision happened at 2 points of same node)
I would rewrite your code like this to avoid such a case (using optionals). Furthermore I slightly rewrote it so you don't have to write 2 if statements for each collision.
func didBeginContact(contact: SKPhysicsContact) {
let firstBody: SKPhysicsBody
let secondBody: SKPhysicsBody
if contact.bodyA.categoryBitMask < contact.bodyB.categoryBitMask {
firstBody = contact.bodyA
secondBody = contact.bodyB
} else {
firstBody = contact.bodyB
secondBody = contact.bodyA
}
if (firstBody.categoryBitMask == PhysicsCategory.Goblin) && (secondBody.categoryBitMask == PhysicsCategory.Bullet) {
collisionWithBullet(firstBody.node as? SKSpriteNode, bullet: secondBody.node as? SKSpriteNode)
}
if (firstBody.categoryBitMask == PhysicsCategory.Goblin) && (secondBody.categoryBitMask == PhysicsCategory.player) {
collisionWithPlayer(firstBody.node as? SKSpriteNode, player: secondBody.node as? SKSpriteNode)
}
}
func collisionWithBullet(goblin: SKSpriteNode?, bullet:SKSpriteNode?){
guard let goblin = goblin, bullet = bullet else { return }
goblin.removeFromParent()
bullet.removeFromParent()
score += 1
scoreLbl.text = "\(score)"
if let explosion = SKEmitterNode(fileNamed: "Goblin Death Animation.sks") {
explosion.particlePosition = goblin.position
self.addChild(explosion)
}
if let fire = SKEmitterNode(fileNamed: "Goblin Death Animation 2.sks") {
fire.particlePosition = goblin.position
self.addChild(fire)
}
}
func collisionWithPlayer(goblin: SKSpriteNode?, player: SKSpriteNode?){
guard let goblin = goblin, player = player else { return }
let scoreDefault = NSUserDefaults.standardUserDefaults()
scoreDefault.setValue(score, forKey: "Score")
// synchronised not needed anymore
if (score > highscore){
let highscoreDefault = NSUserDefaults.standardUserDefaults()
highscoreDefault.setValue(score, forKey: "Highscore")
}
goblin.removeFromParent()
player.removeFromParent()
self.view?.presentScene(EndScene())
scoreLbl.removeFromSuperview()
}
Please also follow the swift guidlines, your methods and properties should start will small letters not will capital letters.
Hope this helps
I have been stuck in this part, I have been trying to removeFromParent but it doesnt work. In my game when an enemy colide 3 times with the player the game is over, the problem is that the enemies continue coming for some seconds and then dissapear but continue makeing damage to the player.
func didBeginContact(contact: SKPhysicsContact) {
let body1 = contact.bodyA.node as! SKSpriteNode
let body2 = contact.bodyB.node as! SKSpriteNode
if ((body1.name == "circuloPrincipal") && (body2.name == "enemigo")) {
colisionPrincipal(body2)
}else {
((body1.name == "enemigo") && (body2.name == "circuloPrincipal"))
colisionPrincipal(body1)
}
}
func colisionPrincipal(enemigo: SKSpriteNode) {
if hits < 2 && circuloPrincipal.color != enemigo.color{
shakeFrame(scene!)
circuloPrincipal.runAction(SKAction.scaleBy(1.5, duration:0.5))
enemigo.removeFromParent()
let particula = SKEmitterNode(fileNamed: "particulas.sks")
particula?.position = enemigo.position
particula?.hidden = false
particula?.runAction(SKAction.fadeOutWithDuration(0.8))
self.addChild(particula!)
hits += 1
}else if circuloPrincipal.color == enemigo.color {
enemigo.physicsBody?.affectedByGravity = false
enemigo.physicsBody?.dynamic = true
enemigo.removeFromParent()
score += 1
scoreLabel.text = "\(score)"
}else {
shakeFrame(scene!)
gameStarted = false
enemigo.removeFromParent()
enemigoTimer.invalidate()
highscoreLabel.runAction(SKAction.fadeInWithDuration(0.5))
if score > highscore {
let highscoreDefault = NSUserDefaults.standardUserDefaults()
highscore = score
highscoreDefault.setInteger(highscore, forKey: "highscore")
highscoreLabel.text = "Best: \(highscore)"
}
}
}
OK, so I don't have all that much information about your game to go by, but if you don't want the enemies to keep damaging the player the quick and dirty fix would be to add a guard to the top of your didBeginContact function:
func didBeginContact(contact: SKPhysicsContact) {
guard hits < 3 else {
return
}
let body1 = contact.bodyA.node as! SKSpriteNode
let body2 = contact.bodyB.node as! SKSpriteNode
if ((body1.name == "circuloPrincipal") && (body2.name == "enemigo")) {
colisionPrincipal(body2)
}else {
((body1.name == "enemigo") && (body2.name == "circuloPrincipal"))
colisionPrincipal(body1)
}
}
This should at least prevent anything to get called based on contacts after the required number of hits have occurred. As for cleaning up the sprites, this sounds rather simple (removeFromParent at the appropriate time) but I haven't got a clue about how you handle your game-states so it's hard to comment any further.
Personally I'd trigger it from the update() function if the required state has happened...
So I am creating an air hockey game and there are 5 major SKSpriteNodes. I need to detect collision between the puck and goal1 and goal2. When it does detect collision it needs to add 1 to the scoreLeft or scoreRight which are SKLabelNode's. I have used the Gamescene.sks file to make the visual representation. I commented the didBeginContact because thats where it doesn't work. Thank You in advance.
class GameScene: SKScene, SKPhysicsContactDelegate {
let paddle1CategoryName = "paddle1"
let paddle2CategoryName = "paddle2"
let puckCategoryName = "puck"
let goal1CategoryName = "goal1"
let goal2CategoryName = "goal2"
let scoreLeftCategoryName = "scoreLeft"
let scoreRightCategoryName = "scoreRight"
var isFingerOnPaddle1 = false
var isFingerOnPaddle2 = false
var paddle1Category: UInt32 = 0x1 << 0
var paddle2Category: UInt32 = 0x1 << 1
var puckCategory: UInt32 = 0x1 << 2
var goal1Category: UInt32 = 0x1 << 3
var goal2Category: UInt32 = 0x1 << 4
override func didMoveToView(view: SKView) {
/* Setup your scene here */
let borderBody = SKPhysicsBody(edgeLoopFromRect: self.frame)
borderBody.friction = 0
self.physicsBody = borderBody
let paddle1 = childNodeWithName(paddle1CategoryName) as! SKSpriteNode
let paddle2 = childNodeWithName(paddle2CategoryName) as! SKSpriteNode
let puck = childNodeWithName(puckCategoryName) as! SKSpriteNode
let goal1 = childNodeWithName(goal1CategoryName) as! SKSpriteNode
let goal2 = childNodeWithName(goal2CategoryName) as! SKSpriteNode
let scoreLeft = childNodeWithName(scoreLeftCategoryName) as! SKLabelNode
let scoreRight = childNodeWithName(scoreRightCategoryName) as! SKLabelNode
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
/* Called when a touch begins */
var touch = touches.first! as UITouch
var location = touch.locationInNode(self)
if let body = physicsWorld.bodyAtPoint(location){
if body.node!.name == paddle1CategoryName {
print("The game has begun.")
isFingerOnPaddle1 = true
} else if body.node!.name == paddle2CategoryName{
print("The game has begun.")
isFingerOnPaddle2 = true
}
}
}
override func touchesMoved(touches: Set<UITouch>, withEvent event: UIEvent?) {
let paddle1 = childNodeWithName(paddle1CategoryName) as! SKSpriteNode
let paddle2 = childNodeWithName(paddle2CategoryName) as! SKSpriteNode
let puck = childNodeWithName(puckCategoryName) as! SKSpriteNode
let goal1 = childNodeWithName(goal1CategoryName) as! SKSpriteNode
let goal2 = childNodeWithName(goal2CategoryName) as! SKSpriteNode
var touch = touches.first! as UITouch
var touchLocation = touch.locationInNode(self)
var previousLocation = touch.previousLocationInNode(self)
if isFingerOnPaddle1{
let paddle1X = paddle1.position.x + (touchLocation.x - previousLocation.x)
let paddle1Y = paddle1.position.y + (touchLocation.y - previousLocation.y)
if (touchLocation.x <= paddle1.position.x && (touchLocation.y <= paddle1.position.y || touchLocation.y >= paddle1.position.y)){
paddle1.position = CGPoint(x: paddle1X, y: paddle1Y)
}
}
if isFingerOnPaddle2{
let paddle2X = paddle2.position.x + (touchLocation.x - previousLocation.x)
let paddle2Y = paddle2.position.y + (touchLocation.y - previousLocation.y)
if (touchLocation.x >= paddle2X && (touchLocation.y >= paddle2Y || touchLocation.y < paddle2.position.y)){
paddle2.position = CGPoint(x: paddle2X, y: paddle2Y)
}
}
}
/*
func didBeginContact(contact: SKPhysicsContact) {
let scoreLeft = childNodeWithName(scoreLeftCategoryName) as! SKLabelNode
let scoreRight = childNodeWithName(scoreRightCategoryName) as! SKLabelNode
var score = 0
let contactMask = contact.bodyA.categoryBitMask | contact.bodyB.categoryBitMask
switch contactMask{
case puckCategory | goal1Category:
if contact.bodyA.categoryBitMask == puckCategory{
puckCategory = contact.bodyA.categoryBitMask
goal1Category = contact.bodyB.categoryBitMask
score++
scoreRight.text = "\(score)"
}else{
puckCategory = contact.bodyB.categoryBitMask
goal1Category = contact.bodyA.categoryBitMask
score++
scoreRight.text = "\(score)"
}
case puckCategory | goal2Category:
if contact.bodyA.categoryBitMask == puckCategory{
puckCategory = contact.bodyA.categoryBitMask
goal2Category = contact.bodyB.categoryBitMask
score++
scoreLeft.text = "\(score)"
}else{
puckCategory = contact.bodyB.categoryBitMask
goal2Category = contact.bodyA.categoryBitMask
score++
scoreLeft.text = "\(score)"
}
default:
// Nobody expects this, so satisfy the compiler and catch
// ourselves if we do something we didn't plan to
fatalError("other collision: \(contactMask)")
}
}*/
override func update(currentTime: CFTimeInterval) {
/* Called before each frame is rendered */
}
}
One issue is using a local var score = 0 at the beginning of your function. Remove it. The score should be stored in the game's model so that logic about winning can be applied but matching your code, at least do this.
if let score = Int(scoreLeft.text) {
scoreLeft.text = "\(score + 1)"
}
Additionally there is a problem with
case puckCategory | goal1Category:
if contact.bodyA.categoryBitMask == puckCategory{
puckCategory = contact.bodyA.categoryBitMask
What you are saying is if contact.bodyA.categoryBitMask is equal to puckCategory, then set puckCategory to contact.bodyA.categoryBitMask. That is a no-op, nothing changes AND more importantly you don't want to change the bit masks that your child nodes are compared against. Make puckCategory, goal1Categoy, and goal2Category constants. Good luck.
Follow Up To OP Comment:
So, throw away the code in didBeginContact that set the category mask variables for two reasons. 1) Setting variables like puckCatergory to their same value is wasteful and confusing. 2) Since variables like puckCategory are compared to child node bit masks, it would be disasterous if they ever did change. That function should look like this. Also be sure and add handlers for the other types of contacts before you get too far.
func didBeginContact(contact: SKPhysicsContact) {
let contactMask = contact.bodyA.categoryBitMask | contact.bodyB.categoryBitMask
switch contactMask {
case puckCategory | goal1Category:
let scoreRight = childNodeWithName(scoreRightCategoryName) as! SKLabelNode
if let score = Int(scoreRight.text) {
scoreRight.text = "\(score + 1)"
}
case puckCategory | goal2Category:
let scoreLeft = childNodeWithName(scoreLeftCategoryName) as! SKLabelNode
if let score = Int(scoreLeft.text) {
scoreLeft.text = "\(score + 1)"
}
default:
// There are other contacts that need to be handled; paddle+puck,puck+wall, etc
fatalError("other collision: \(contactMask)")
}
}
how can i change my spritekit on collision in spritekit swift.
else if collidedBird.birdType == 6 {
if UIDevice.currentDevice().userInterfaceIdiom == .Pad
{
_bird.physicsBody?.applyImpulse(CGVectorMake(0, birdImpluseReturn(70.0)))
} else {
_bird.physicsBody?.applyImpulse(CGVectorMake(0, birdImpluseReturn(70.0)))
}
let fire = NSTimer.scheduledTimerWithTimeInterval(0.05, target: self, selector: Selector("createDragonFire"), userInfo: nil, repeats: false)
playEffectSound("BS_Std_Jump_SFX.mp3")
_platform.removeFromParent()
}
If you want to change the Image of the Sprite, then you should use SKPhysicsContactDelegate Method.
In General that means that you have to implement the SKPhysicsContactDelegate, Make a new Struct:
For Example:
struct PhysicCategories {
static let NoneC : UInt32 = 0x1 << 0
static let Bird : UInt32 = 0x1 << 1
static let PlatformC : UInt32 = 0x1 << 2
static let FinishC : UInt32 = 0x1 << 3
static let ObstacleC : UInt32 = 0x1 << 4
}
then go in your didMoveToView() function and write:
PhysicsWorld.contactdelegate = self
Dont forget to make this Step!
Then add the func
func didBeginContact(contact: SKPhysicsContact) {
var contactbody1 = contact.bodyA
var contactbody2 = contact.bodyB
if contactbody1.categoryBitMask < contactbody2.categoryBitMask{
contactbody1 = contact.bodyA
contactbody2 = contact.bodyB
} else {
contactbody1 = contact.bodyB
contactbody2 = contact.bodyA
}
if ((contactbody1.categoryBitMask == PhysicCategories.BirdC) && (contactbody2.categoryBitMask == PhysicCategories.ObstacleC)){
// Make a GameOver Function for that!
// GameOver()
}
if ((contactbody1.categoryBitMask == PhysicCategories.BirdC) && (contactbody2.categoryBitMask == PhysicCategories.PlatformC)){
contactbody1.node.texture = SKTexture(imageNamed: "")
}