iossprite-kitskphysicsbodyskphysicsworld

Sprite Kit didBeginContact not called between body and edgeRect


I have a game where I'm flicking bodies off the screen. I want to detect when these bodies are coming into contact with the edges (still letting the bodies pass through to off the screen) of the screen and I've implemented everything but still it is not working..here's my code:

GameScene.h

 typedef NS_OPTIONS(uint32_t, FAPhysicsCategory) {
FAWallCategory = 1 << 0,
FABottomWallCategory = 1 << 1,
FAAnimalCategory = 1 << 2,
};

 GameScene : SKScene <SKPhsyicsContactDelegate>

GameScene.m

-(void)setupWorldPhysics
{
// Set world gravity
self.physicsWorld.gravity = CGVectorMake(0.0, -5.0);

float bottomOffset = 400.0;
CGRect newFrame = CGRectMake(0, -bottomOffset, self.frame.size.width, self.frame.size.height + bottomOffset);
self.physicsBody = [SKPhysicsBody bodyWithEdgeLoopFromRect:newFrame];
self.physicsBody.categoryBitMask = FAWallCategory;
self.physicsBody.contactTestBitMask = FAAnimalCategory;
self.physicsBody.collisionBitMask = 0;
}

 -(void)launchBody {
     SKSpriteNode* animalSprite = [SKSpriteNode spriteNodeWithImageNamed:[animalImagesArray objectAtIndex:animalChoice]];
    animalSprite.position = CGPointMake(self.size.width/2, -animalSprite.size.height);
    animalSprite.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:25];
    animalSprite.physicsBody.dynamic = YES;
    animalSprite.physicsBody.allowsRotation = YES;
    animalSprite.name = @"animalSprite";
    animalSprite.physicsBody.categoryBitMask = FAAnimalCategory;
    animalSprite.physicsBody.contactTestBitMask = FAWallCategory;
    animalSprite.physicsBody.collisionBitMask = 0;
    animalSprite.physicsBody.usesPreciseCollisionDetection = YES;
    [self addChild:animalSprite];
 }

Solution

  • Alright so it's late and I'm exhausted and I feel like an idiot..i was missing:

    self.physicsWorld.contactDelegate = self;
    

    tool