2014-09-29 60 views
0

我有一個SKSpriteNode碰撞並從另一個SKSpriteNode反彈。我想要的是能夠檢測到碰撞,但沒有反彈。我希望它反彈其他節點,但不是這個。那可能嗎?防止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

設置collisionBitMask和這兩個機構 喜歡的contactTestBitMask

self.zone.collisionBitMask = 0xFFFFFFFF & (~ballCategory); 
self.ball.collisionBitMask = 0xFFFFFFFF & (~zoneCategory); 
self.zone.contactTestBitMask = ballCategory; 

那麼當發生接觸時預計的SKPhysicsContactDelegatedidBeginContact:調用。 將不會有collsion。

+1

你應該這樣做:self.zone.collisionBitMask&=〜ballCategory; – 0x141E 2014-09-30 18:28:38