Dinodefense Ch19 Pathfinding: set<GKEntity> no sort

Hello. DinoDefense coders,

During the challenge 2 in Chapter 19 Pathfinding, there is a piece of code which is used to sort all entities in the scene by y-position.

in GameScene.swift

override func didFinishUpdate() {

// 1
let ySortedEntities = entities.sort {
let nodeA = $0.0.componentForClass(SpriteComponent.self)!.node
let nodeB = $0.1.componentForClass(SpriteComponent.self)!.node
return nodeA.position.y > nodeB.position.y
}
}

There is an error in swift 4 or 5:

here is the definition of entities:

var entities = Set< GKEntity >()

I’ve just checked the GKEntity and found only ‘sorted’ provided.
the thing is ,however, I don’t know how to fix this problem.
Anyone can help?
Thanks.!

This topic was automatically closed after 166 days. New replies are no longer allowed.