I have a very simple project using SpriteKit where a monster is dropped and walks across a platform. On the iPhone, didBeginContact gets called once when the monster hits the platform. However, on the iPad, the method gets called several times a second as the monster slides across the platform. Why is it fine on the iPhone but buggy on the iPad? I've tested on both the simulator and an actual iPad.
Here is where I set up the Categories
static const uint32_t playerCategory = 0x1 << 0;
static const uint32_t bulletCategory = 0x1 << 1;
static const uint32_t monsterCategory = 0x1 << 2;
static const uint32_t platformCategory = 0x1 << 3;
static const uint32_t worldCategory = 0x1 << 4;
Here are the settings for the monster
enemy.physicsBody.dynamic = YES;
enemy.physicsBody.affectedByGravity = YES;
enemy.physicsBody.allowsRotation = NO;
enemy.physicsBody.categoryBitMask = monsterCategory;
enemy.physicsBody.contactTestBitMask = worldCategory & platformCategory & bulletCategory;
enemy.physicsBody.collisionBitMask = platformCategory;
Here is how the monster gets moved
enemy.physicsBody.velocity = CGVectorMake(100, 0);
And here is how I know didBeginContact gets called constantly. I get a log 5 times every second saying monster hit platform. I need to fix this for when I implement new things later.
if (firstBody.categoryBitMask == monsterCategory && secondBody.categoryBitMask == platformCategory) { NSLog(@"Monster Hit Platform"); }