以下代码无法按预期工作。因为我无法理解的原因“怪物交叉玩家”从未被称为。这是怎么回事?
for monsterNode in self.children as [SKNode]{
if (monsterNode.name? == "monster") {
println("monster node found")
for playerNode in self.children as [SKNode]{
if (playerNode.name? == "player"){
println("player found")
if(monsterNode.intersectsNode(playerNode)){
println("monster intersects player")
}
}
}
}
}
对于玩家节点与怪物节点相交的一个玩家节点和三个怪物节点,将打印以下内容:
monster node found
player found
monster node found
player found
monster node found
player found