我正在使用 Apple Sprite Kit 编写一个小游戏。
我遇到了碰撞问题。有时我不希望两个带有physicsBodys 的skSpriteNodes 交互。
例如,我有 HERO、ENEMYS 和 SHOTS,我希望 SHOTS 只与 ENEMYS 交互。
但是当 2 个镜头碰撞在一起时,它们会改变位置。!
拍摄的代码是
shot.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:shot.size];
shot.physicsBody.dynamic = YES;
shot.physicsBody.allowsRotation = FALSE;
shot.physicsBody.categoryBitMask = playerShotCategory;
shot.physicsBody.contactTestBitMask = enemyCategory;
敌人的代码是
activeGameObject.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:activeGameObject.size];
activeGameObject.physicsBody.dynamic = YES;
activeGameObject.physicsBody.categoryBitMask = enemyCategory;
activeGameObject.physicsBody.contactTestBitMask = playerCategory | playerShotCategory;
activeGameObject.physicsBody.allowsRotation = FALSE;