我正在创建一个需要使用大量碰撞检测的游戏,而我今天才了解它。
现在我有两个SKSpriteNodes
,但一个是SKNode
. SKSpriteNode
调用没有父级的精灵,调用有父级character
的精灵buildingStructure
。
现在character
的类别是static const uint32_t playerCategory = 0x1 << 20;
和buildingStructure
的类别是_buildingStructureCategory = 0x1 << 0;
。buildingStructure
的类别map.m
通过 a设置在另一个类中@property
。
变量正确地传递给另一个名为main.m
的类(这是character
设置类别的地方)。我character
用一种方法创建,设置他的物理体、位置等。
character
的属性
character.name = @"character";
character.size = CGSizeMake(250, 400);
character.zPosition = 500;
character.position = CGPointMake(self.scene.size.width/2, self.scene.size.height/2+200);
character.physicsBody = [SKPhysicsBody bodyWithRectangleOfSize:character.size];
character.physicsBody.restitution = 0;
character.physicsBody.density = 0.1;
character.physicsBody.allowsRotation = NO;
character.physicsBody.categoryBitMask = playerCategory;
character.physicsBody.collisionBitMask = categoryBitManager.buildingStructureCategory;
buildingStructure
的属性
buildingStructure.name = @"buildingStructure";
buildingStructure.position = CGPointMake(building.position.x, building.position.y);
buildingStructure.size = CGSizeMake(500, 400);
buildingStructure.physicsBody.dynamic = NO;
buildingStructure.physicsBody.categoryBitMask = _buildingStructureCategory;
另一方面buildingStructure
,没有设置physicsBody
,因为我想character
通过,buildingStructure
但我也希望它检测何时character
“处于顶部”buildingStructure
以执行操作。
由于buildingStructure
没有定义physicsBody
这是导致didBeginContact:contact
无法识别碰撞接触的原因吗?