1

The following code doesn't work as expected. For reason incomprehensible to me "monster intersect player" is never called. What's the matter here?

            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")
                            }
                        }
                    }
                }
            }

For one player node and three monster nodes where the player node is intersecting a monster node, the following is printed:

monster node found
player found
monster node found
player found
monster node found
player found
CodeSmile
  • 64,284
  • 20
  • 132
  • 217
user3673836
  • 591
  • 1
  • 9
  • 23
  • Check (log) the frame properties of both monsterNode and playerNode to see whether they are indeed not overlapping. If one of the two is a SKNode the frame property will most likely be a rect with zero width/height. – CodeSmile Dec 09 '14 at 17:32
  • Thanks! That infact seems to be the case! monster position x: 660.825134277344 y:212.508346557617 and player position x: 0.0 y:0.0 I still don't understand why though. Where did I go wrong? – user3673836 Dec 09 '14 at 18:55

0 Answers0