2

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];
 }
Mike Simz
  • 3,976
  • 4
  • 26
  • 43
  • I want to say that I've looked through all the other questions regarding -didBeginContact not being called and none of them have solved my issue..is there no way to catch a contact between a body and the an edgeRect? – Mike Simz Nov 19 '14 at 04:57

1 Answers1

2

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

self.physicsWorld.contactDelegate = self;

tool

Mike Simz
  • 3,976
  • 4
  • 26
  • 43