SKPhysics机身无碰撞检测

时间:2014-12-23 05:49:57

标签: objective-c sprite-kit skphysicsbody

我正在尝试创建一个下降然后停在屏幕底部的圆圈,但圆圈却不断下降。有什么想法吗?

我已更新代码以显示更新的位掩码:

-(void)didMoveToView:(SKView *)view {
self.physicsBody = [SKPhysicsBody bodyWithEdgeLoopFromRect:self.frame];
self.physicsBody.categoryBitMask = EDGE_BIT_MASK;
self.physicsBody.collisionBitMask = BUBBLE_BIT_MASK | BALL_BIT_MASK;
self.physicsBody.dynamic = NO;
self.physicsBody.friction = 0.0;

self.physicsWorld.contactDelegate = self;
}

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

UITouch * touch = [touches anyObject];
CGPoint touchLocation = [touch locationInNode:self];

growingNode = [SKShapeNode node];
growingNode.path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(touchLocation.x, touchLocation.y, 100, 100)].CGPath;
growingNode.strokeColor = [UIColor whiteColor];
growingNode.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:growingNode.frame.size.width / 2];
growingNode.physicsBody.dynamic = true;
growingNode.physicsBody.restitution = 0.2;
growingNode.physicsBody.friction = 0.0;
growingNode.physicsBody.allowsRotation = NO;
growingNode.physicsBody.linearDamping = 0.0;
growingNode.physicsBody.collisionBitMask = EDGE_BIT_MASK | BALL_BIT_MASK;
growingNode.physicsBody.categoryBitMask = BUBBLE_BIT_MASK;
growingNode.physicsBody.contactTestBitMask = BALL_BIT_MASK;
growingNode.physicsBody.usesPreciseCollisionDetection = YES;
growingNode.physicsBody.affectedByGravity = YES;
growingNode.physicsBody.mass = growingNode.frame.size.width / self.frame.size.width;


[self addChild:growingNode];
}

1 个答案:

答案 0 :(得分:2)

您需要相应地设置边缘和气泡节点的碰撞位掩码值:

self.physicsBody.collisionBitMask = BUBBLE_BIT_MASK;

growingNode.physicsBody.collisionBitMask = BALL_BIT_MASK | EDGE_BIT_MASK;