Class

GKMeshGraph

A navigation graph for 2D game worlds that creates a space-filling network for smooth pathfinding around obstacles.

Declaration

@interface GKMeshGraph<__covariant NodeType> : GKGraph

Overview

To use a mesh graph for pathfinding, add a collection of GKObstacle objects representing impassable areas and GKGraphNode2D objects representing points of interest (such as the current position of a game character and the location it needs to find a route to). Then use methods of the superclass GKGraph to find routes through the graph.

Unlike the related GKObstacleGraph class, a mesh graph creates a space-filling network of graph nodes, resulting in paths that are smooth but not the most efficient.

To learn more about graphs and pathfinding, see Pathfinding in GameplayKit Programming Guide.

Topics

Creating a Graph

- initWithBufferRadius:minCoordinate:maxCoordinate:nodeClass:

Initializes a graph to cover the specified area, using the specified node class.

+ graphWithBufferRadius:minCoordinate:maxCoordinate:nodeClass:

Creates a graph to cover the specified area, using the specified node class.

- initWithBufferRadius:minCoordinate:maxCoordinate:

Initializes a graph to cover the specified area.

+ graphWithBufferRadius:minCoordinate:maxCoordinate:

Creates a graph to cover the specified area.

Working with Obstacles

obstacles

The list of obstacle objects in the graph, each of which describes a polygon-shaped impassable area.

- addObstacles:

Adds new obstacles to the graph.

- removeObstacles:

Removes the specified obstacle from the graph.

Working with Nodes

- connectNodeUsingObstacles:

Adds the specified node to the graph, connecting it to its nearest neighbors without creating connections that pass through obstacles or their buffer regions.

bufferRadius

The distance from obstacle edges that should also be considered impassable.

Managing the Mesh

- triangulate

Creates or updates the graph with a network of nodes that describes the open space around its obstacles.

triangulationMode

A set of options for how to place graph nodes when triangulating the graph.

- triangleAtIndex:

The triangle definition at the specified index.

triangleCount

The number of triangles in the mesh.

Constants

GKMeshGraphTriangulationMode

Options for how to place graph nodes when generating the graph, used by the triangulationMode property.

GKTriangle

The definition of a triangle in the mesh, available with the triangleAtIndex: method.

Relationships

Inherits From

See Also

Pathfinding

GKGraph

A collection of nodes that describes the navigability of a game world and provides pathfinding methods to search for routes through that space.

GKObstacleGraph

A navigation graph for 2D game worlds that creates a minimal network for precise pathfinding around obstacles.

GKGridGraph

A navigation graph for 2D game worlds where movement is constrained to an integer grid.

GKGraphNode

A single node in a navigation graph for use in pathfinding.

GKGraphNode2D

A node in a navigation graph, associated with a point in continuous 2D space.

GKGraphNode3D

A node in a navigation graph, associated with a point in continuous 3D space.

GKGridGraphNode

A node in a navigation graph, associated with a position on a discrete two-dimensional grid.