我正在使用苹果的Sprite Kit编写一个小游戏。
我在碰撞检测方面遇到了麻烦。 有时我不希望两个具有physicsBodys属性的skSpriteNodes相互作用。
例如,我有一个HERO(英雄),ENEMYS(敌人)和SHOTS(射击),我只希望SHOTS与ENEMYS相互作用。
但是当两个子弹相互碰撞时,它们会改变位置!
子弹的代码如下:
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;