我有一个SKSpriteNode碰撞并从另一个SKSpriteNode反弹。我想要的是能够检测到碰撞,但不能让它反弹。我想让它从其他节点反弹,但不是这个节点。这可能吗?
self.physicsWorld.contactDelegate = self;
self.physicsBody = [SKPhysicsBody bodyWithEdgeLoopFromRect:self.frame];
self.physicsWorld.gravity = CGVectorMake(0.0f, 0.0f);
self.zone = [SKSpriteNode spriteNodeWithImageNamed:@"Oval.png"];
self.zone.position = CGPointMake(CGRectGetMidX(self.frame),CGRectGetMidY(self.frame)); self.zone.xScale = 0.3;
self.zone.yScale = 0.3;
self.zone.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:self.zone.frame.size.width/2];
self.zone.physicsBody.restitution = 0.0f;
self.zone.physicsBody.density = 0;
self.zone.physicsBody.friction = 0.4f;
self.zone.physicsBody.categoryBitMask = zoneCategory;
self.zone.physicsBody.dynamic = NO;
self.ball = [SKSpriteNode spriteNodeWithImageNamed:@"Ball.png"];
self.ball.position = CGPointMake(80,0);
self.ball.name = @"BallNode";//how the node is identified later
self.ball.physicsBody = [SKPhysicsBody bodyWithCircleOfRadius:self.ball.frame.size.width/2];
self.ball.physicsBody.restitution = 0.1f;
self.ball.physicsBody.friction = 0.4f;
self.ball.physicsBody.categoryBitMask = ballCategory;
self.ball.physicsBody.dynamic = NO;
我不希望球和区域反弹。有什么想法吗?
答案 0 :(得分:0)
设置这两个机构的collisionBitMask
和contactTestBitMask
像:
self.zone.collisionBitMask = 0xFFFFFFFF & (~ballCategory);
self.ball.collisionBitMask = 0xFFFFFFFF & (~zoneCategory);
self.zone.contactTestBitMask = ballCategory;
然后,当发生联系时,您需要在didBeginContact:
中拨打SKPhysicsContactDelegate
。
没有collsion。