Drop Charge didBeginContact(_:)

I’ve been playing around with the didBeginContact(_:slight_smile: function in the drop charge project. I’m trying to find a way to make the breakable platform break if the player makes contact from below the block as well as landing on the block. The behavior from the book makes the block break only if you land on it and the player pass through the block when jumping. So I’m wondering how to make the block break if the player runs into the block from below. This would be similar to how traditional games like mario bros deals with breaking blocks.

Here’s the didBeginContact(_:slight_smile: function and . Do you have to enable a collisionBitMask as well as a contactBitMask for the block and player to do this?

func didBeginContact(contact: SKPhysicsContact) {
let other = contact.bodyA.categoryBitMask == PhysicsCategory.Player ? contact.bodyB : contact.bodyA
switch other.categoryBitMask {
case PhysicsCategory.CoinNormal:
if let coin = other.node as? SKSpriteNode {
emitParticles(“CollectNormal”, sprite: coin)
jumpPlayer()
runAction(soundCoin)
score += 2
}
case PhysicsCategory.CoinSpecial:
if let coin = other.node as? SKSpriteNode {
emitParticles(“CollectSpecial”, sprite: coin)
boostPlayer()
runAction(soundBoost)
score += 5
}
case PhysicsCategory.PlatformNormal:
if let platform = other.node as? SKSpriteNode {
if player.physicsBody!.velocity.dy < 0 {
platformAction(platform, breakable: false)
jumpPlayer()
runAction(soundJump)
}
}
case PhysicsCategory.PlatformBreakable:
if let platform = other.node as? SKSpriteNode {
if player.physicsBody!.velocity.dy < 0 {
platformAction(platform, breakable: true)
smallJumpPlayer()
runAction(soundBrick)
score += 1
}
}
default:
break;
}
}

I think is is what you need to do. Change the following in the Idles.swift >
override fun didEnterWithPreviousState(previousState: GKState?) {…}

scene.player.physicsBody!.collisionBitMask = 0

scene.player.physicsBody!.collisionBitMask = PhysicsCategory.PlatformBreakable

Is there more to this?