swiftsprite-kitpath-findingtiledsktilemapnode

Pathfinding on Tilemap with GameplayKit


I am using SKTilemapNode. How I can use the Pathfinding with GameplayKit properly?

Some Info: Walls are all tiles and no tiles are 'ways'


Solution

  • The basic idea is to create a SKGridGraph of connected nodes, then remove the nodes that can't be walked on. The GameplayKit Guide shows an example (Listing 6-1 Generating a Grid Graph). So in your case using SKTilemapNode the graphs width and height is determined by the number of tile wide and high on the map e.g. if your map is 32 tiles wide and 18 tiles high, then initialise the graph with width of 32 and height of 18.