如何让我的SKnode只碰撞一次?我有一个粒子系统,当它们发生碰撞时会出现,但是如果它们再次碰撞就会出现一堆。我不希望这样。只想要一个然后就可以了。我该如何解决这个问题呢?
if bodyA.categoryBitMask == 1 && bodyB.categoryBitMask == 3 || bodyA.categoryBitMask == 3 && bodyB.categoryBitMask == 1 {
print("END GAME")
if let dieexplostionNode = SKEmitterNode(fileNamed: "Explosion.sks"){
dieexplostionNode.targetNode = self
dieexplostionNode.position = player.position
// add 3 actions
let wait = SKAction.wait(forDuration: 1.1)
let addExplosion = SKAction.run {
self.player.addChild(dieexplostionNode)
self.player.alpha = 0
}
let removePlayer = SKAction.run {
self.player.removeFromParent()
self.player.removeAllActions()
dieexplostionNode.removeFromParent()
}
// put them in a sequence.
let seq = SKAction.sequence([addExplosion,wait,removePlayer])
// run the sequence
self.run(seq)
}
答案 0 :(得分:2)
您的问题是可能发生多个联系人,因此您需要检查代码以告知您的系统您已经评估了联系人并且不想进行任何其他评估。我首选的方法是在类别位掩码标志上保留第31位,如果设置了,则不要进行评估。
var data={
dataUpdatedTime: "2017-07-11T15:47:00+03:00",
weatherStations: [
{
id: 2050,
measuredTime: "2017-07-11T15:44:00+03:00",
sensorValues: [
{
id: 1,
roadStationId: 2050,
name: "ILMA",
oldName: "airtemperature1",
shortName: "Ilma ",
sensorValue: 18.2,
sensorUnit: "°C"
},
{
id: 2,
roadStationId: 2050,
name: "ILMA_DERIVAATTA",
oldName: "airtemperature1change",
shortName: "DIlm",
sensorValue: 0.2,
sensorUnit: "°C/h"
},
{
id: 3,
roadStationId: 2050,
name: "TIE_1",
oldName: "roadsurfacetemperature1",
shortName: "Tie1 ",
sensorValue: 20.5,
sensorUnit: "°C"
}
]
}
]
}
function findByName(name){
return data.weatherStations[0].sensorValues.filter((item)=>item.name==name);
}
console.log(findByName('ILMA'))