本文介绍了防止SKNode相互施加压力的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个SKNode
对象.发生碰撞时,它们的位置会发生变化.
I have two SKNode
objects. Their positions change when they collide.
如何防止这种情况?同时,我仍然希望能够通过- (void)didBeginContact
;
How can I prevent that? At the same time, I still want to be able to respond to them contacting via - (void)didBeginContact
;
我尝试将它们的mass
属性都设置为0.0f
,但这没用.
I tried setting both their mass
property to 0.0f
but that didn't work.
推荐答案
您可以通过设置类别,冲突和接触位掩码来实现.
You can achieve that by setting category, collision and contact bit masks.
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.
In above case bodyA and bodyB cannot collide, but you will receive didBeginContact once they are in contact.
这篇关于防止SKNode相互施加压力的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!