func checkCollisions() {
var hitCats: [SKSpriteNode] = []
enumerateChildNodes(withName: "cat") { node, _ in
let cat = node as! SKSpriteNode
if cat.frame.intersects(self.zombie.frame) {
hitCats.append(cat)
}
}
for cat in hitCats {
zombieHit(cat: cat)
}
var hitEnemies: [SKSpriteNode] = []
enumerateChildNodes(withName: "enemy") { node, _ in
let enemy = node as! SKSpriteNode
if node.frame.insetBy(dx: 20, dy: 20).intersects(
self.zombie.frame) {
hitEnemies.append(enemy)
}
2D Apple Games by Tutorials Chapter 3: Actions
raywenderlich.com 106
}
for enemy in hitEnemies {
zombieHit(enemy: enemy)
}
}
I just wanted to indicate that in XCode 9.1 with the checkCollision() function on page 106 and 107 [Collision Detection section], that the two references to self.zombie.frame don’t compile. Changing to just zombie.frame seems to fix the issue. Why should self be needed here?
I have zombie as a property at the beginning of the file.