hka hka - 1 year ago 88
Swift Question

contactTestBitMask not detecting in didBeginContact (Logs) in SpriteKit with Swift

I’m making a simple spriteKit game and I have all my physicsBodies set up. I have added the proper categoryBitMasks and ContactTestBitMask to detect contact.

When I run the app I have contact but it does not show in the Logs for didBeginContact where I added print(“contact”)

I cant seem to get by this. I have looked over probably all the questions and tutorials most similar to this.

I have tried 2 different methods

enum ColliderType : UInt32 {
case None = 0
case All = 0xFFFFFFFF
case enemy = 0b001
case hero = 0b010
case screen = 0b100


let heroCategory :UInt32 = 0x1 << 0
let screenCategory:UInt32 = 0x1 << 1
let enemyCategory:UInt32 = 0x1 << 2
let scoreCategory:UInt32 = 0x1 << 3

Its strange how I have contact but it doesn’t print in the logs.

I have a moving background, moving enemies coming towards the hero. The hero moves to dodge the enemies.

I tried adding a “gameOver” function to see if it will stop the game by setting

if self.movingParts.speed > 0 {
self.movingParts.speed = 0

And setting the speed in touchesBegan function

I can upload the code if needed. Please let me know.

Any kind of help is appreciated. Thanks

hka hka
Answer Source

Ok after 17 days I finally figured it out a solution that really wasn't my fault.

All I did was erase

func didBeginContact(contact: SKPhysicsContact) {

And RE-TYPED IT. Wow, strange but it worked. I have noticed this issue with other problems (re-typing the code for it to work).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download