Class

GKObstacleGraph

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

Declaration

@interface GKObstacleGraph<__covariant NodeType> : GKGraph

Overview

You create an obstacle graph with a collection of GKObstacle objects. To use the graph for pathfinding, you add 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 GKMeshGraph class, an obstacle graph creates a minimal network of graph nodes, resulting in paths that are efficient but not smooth.

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

Topics

Creating a Graph

- initWithObstacles:bufferRadius:nodeClass:

Initializes a graph with the specified list of obstacles, using the specified node class.

+ graphWithObstacles:bufferRadius:nodeClass:

Creates a graph with the specified list of obstacles, using the specified node class.

- initWithObstacles:bufferRadius:

Initializes a graph with the specified list of obstacles.

+ graphWithObstacles:bufferRadius:

Creates a graph with the specified list of obstacles.

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.

- removeAllObstacles

Removes all obstacles from the graph.

- nodesForObstacle:

Returns the group of nodes corresponding to an obstacle in 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.

- connectNodeUsingObstacles:ignoringObstacles:

Adds the specified node to the graph, connecting it to its nearest neighbors while ignoring the area occupied by the specified obstacles.

- connectNodeUsingObstacles:ignoringBufferRadiusOfObstacles:

Adds the specified node to the graph, connecting it to its nearest neighbors while ignoring the buffer regions around the specified obstacles.

bufferRadius

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

Locking Node Connections

- lockConnectionFromNode:toNode:

Prevents the specified nodes from being disconnected due to the addition of obstacles.

- unlockConnectionFromNode:toNode:

Allows the specified nodes to be disconnected due to the addition of obstacles.

- isConnectionLockedFromNode:toNode:

Returns a Boolean value indicating whether the specified nodes are protected from disconnection due to the addition of obstacles.

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.

GKMeshGraph

A navigation graph for 2D game worlds that creates a space-filling network for smooth 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.