我试图检测我的移动精灵和底部之间的接触。我为底部精灵创建了一个名为worldCategory的类别,之后我使用didBeginContact方法检测碰撞。目前我没有收到关于联系人的任何通知。
首先,我使用位掩码定义类别:
然后我创建底部的SKSpriteNode并创建物理体和类别并使用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方法:
-(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];
}
}
答案 0 :(得分:0)
基于边缘的实体不会生成联系事件。由于您创建了矩形,因此应使用多边形体。