Keep SKNodes from applying force to each other

前端 未结 1 1715
自闭症患者
自闭症患者 2021-01-26 15:43

I have two SKNode objects. Their positions change when they collide.

How can I prevent that? At the same time, I still want to be able to respond to them c

1条回答
  •  离开以前
    2021-01-26 16:46

    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];
    

    In above case bodyA and bodyB cannot collide, but you will receive didBeginContact once they are in contact.

    0 讨论(0)
提交回复
热议问题