Instance Method

initFromGridStartingAt:width:height:diagonalsAllowed:nodeClass:

Initializes a graph that describes an integer grid with the specified dimensions, using the specified node class.

Declaration

- (instancetype)initFromGridStartingAt:(vector_int2)position width:(int)width height:(int)height diagonalsAllowed:(BOOL)diagonalsAllowed nodeClass:(Class)nodeClass;

Parameters

position

The lowest x- and y-coordinates to appear in the grid.

width

The number of possible x-coordinates in the grid.

height

The number of possible y-coordinates in the grid.

diagonalsAllowed

YES to connect nodes in the grid to their diagonal neighbors; NO to connect nodes only to their horizontal and vertical neighbors.

nodeClass

The GKGridGraphNode subclass to use for nodes in the graph.

Return Value

A new grid graph.

Discussion

Use the nodeClass parameter to create a graph using a custom subclass of GKGridGraphNode. For example, your custom node class might override the costToNode: method so that some nodes are more costly than others to travel through. Pathfinding in such a graph would favor indirect routes when a direct route has a higher cost.

All connections created through this method are bidirectional.

See Also

Creating a Graph

+ graphFromGridStartingAt:width:height:diagonalsAllowed:nodeClass:

Creates a graph that describes an integer grid with the specified dimensions, using the specified node class.

- initFromGridStartingAt:width:height:diagonalsAllowed:

Initializes a graph that describes an integer grid with the specified dimensions.

+ graphFromGridStartingAt:width:height:diagonalsAllowed:

Creates a graph that describes an integer grid with the specified dimensions.