本文介绍了防止 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 相互施力的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!