我有9个SKSpritenode,我想检测与另一个SKSpritenode的联系。我将ContactTestBitMask设置为联系,但是从未调用过did开始联系人中的代码。
for i in (0...8){
squares[i].node.position = positions[i]
squares[i].node.physicsBody?.categoryBitMask = physics[i]
squares[i].node.physicsBody = SKPhysicsBody(rectangleOf: squares[i].node.size )
squares[i].node.physicsBody?.affectedByGravity = false
squares[i].node.physicsBody?.isDynamic = false
squares[i].node.physicsBody?.contactTestBitMask = PhysicsCategory.Circle
squares[i].node.physicsBody?.collisionBitMask = 0
squares[i].node.color = squares[i].startColor
squares[i].node.colorBlendFactor = 1.0
squares[i].node.size = CGSize(width: squareUnit, height: squareUnit)
}
答案 0 :(得分:2)
解决您的问题的方法是移动此行(在1234
Brake
66.78
Warehouse A
4
方法中):
createSquares()
在物理实体初始化之后,这里发生:
squares[i].node.physicsBody?.categoryBitMask = physics[i]
并处理这样的联系人:
squares[i].node.physicsBody = SKPhysicsBody(rectangleOf: squares[i].node.size )