检测 SKNode 和粒子之间的碰撞?

Detect collision between SKNode and Particles?

我有这个函数可以创建一些熔岩:

func setupLava() {
    let emitter = SKEmitterNode(fileNamed: "Lava.sks")!
    emitter.particlePositionRange = CGVector(dx: 200, dy: 0.0)
    emitter.advanceSimulationTime(3.0)
    emitter.zPosition = 4
    emitter.position = CGPoint(x: self.frame.width / 2, y: 300)
    lava.addChild(emitter)

}

我想检测玩家何时与其发生碰撞。我该怎么做?

来自文档:

Particles are not represented by objects in SpriteKit. This means you cannot perform node-related tasks on particles, nor can you associate physics bodies with particles to make them interact with other content. Although there is no visible class representing particles added by the emitter node, you can think of a particle as having properties like any other object.

因此您不能使用 SpriteKit 检测与发射的 Lava 的碰撞,但您可以将物理体关联到 Lava 对象并与其碰撞,而不是与单个发射的节点碰撞。使用节点 physicsBodycategoryContactMaskcontactBitMask 字段来检测联系人。