Reputation: 697
I'm trying to detect contact between my mover sprite and the bottom. I've created an category for the bottom sprite called worldCategory and after that i'm detecting collision using didBeginContact method. At the moment i do not get any kind of notification on the contact.
First i define the category using bitmasks:
Then i create the bottom SKSpriteNode and creates the physicsbody andcategory and contaact bitmasks:
static const uint32_t worldCategory = 1 << 1;
bottom = [SKSpriteNode spriteNodeWithColor:[SKColor clearColor] size:CGSizeMake(self.frame.size.width*2, 120)];
bottom.position = CGPointMake(0, 0);
[self addChild:bottom];
bottom.physicsBody = [SKPhysicsBody bodyWithEdgeLoopFromRect:bottom.frame];
bottom.physicsBody.categoryBitMask = worldCategory;
mover.physicsBody.contactTestBitMask = worldCategory;
didBeginContact method:
-(void)didBeginContact:(SKPhysicsContact *)contact {
SKSpriteNode *firstNode, *secondNode;
firstNode = (SKSpriteNode *)contact.bodyA.node;
secondNode = (SKSpriteNode *) contact.bodyB.node;
int bodyAA = contact.bodyA.categoryBitMask;
if (bodyAA == worldCategory) {
NSLog(@"Contact");
SKTransition *reveal = [SKTransition doorsCloseVerticalWithDuration:1.0 ];
EndScene *newScene = [[EndScene alloc] initWithSize: CGSizeMake(self.size.width,self.size.height)];
// Optionally, insert code to configure the new scene.
[self.scene.view presentScene: newScene transition: reveal];
}
}
Upvotes: 0
Views: 38
Reputation: 64477
Edge-based bodies do not generate contact events. Since you create rectangles you should use a polygon body instead.
Upvotes: 0