让SKNodes不要互相施力

时间:2014-02-15 17:10:56

标签: ios macos sprite-kit game-physics

我有两个SKNode个对象。他们的位置在碰撞时会改变。

我该怎样防止这种情况?与此同时,我仍然希望能够通过- (void)didBeginContact;

回复他们

我尝试将mass属性设置为0.0f,但这不起作用。

1 个答案:

答案 0 :(得分:2)

您可以通过设置类别,碰撞和接触位掩码来实现此目的。

uint32_t bodyABitMask = 1<<0;
uint32_t bodyBBitMask = 1<<1;

//A mask that defines which categories this physics body belongs to.
[bodyA setCategoryBitMask:bodyABitMask];
[bodyB setCategoryBitMask:bodyBBitMask];

//A mask that defines which categories of physics bodies 
//can collide with this physics body.
[bodyA setCollisionBitMask:0];
[bodyB setCollisionBitMask:0];

//A mask that defines which categories of bodies cause 
//intersection notifications with this physics body.
[bodyA setContactTestBitMask:bodyBBitMask];
[bodyB setContactTestBitMask:bodyABitMask];

在上面的情况下,bodyA和bodyB不会发生冲突,但是一旦他们联系你就会收到didBeginContact。