SKTiledGraphNode

public class SKTiledGraphNode : GKGridGraphNode, TiledObjectType

The SKTiledGraphNode node is a custom GKGridGraphNode object that adds a weight parameter for use with Tiled scene properties. Can be used with normal GKGridGraphNode instances. The SKTiledGraphNode.weight property is used to affect the estimated cost to a connected node. (Increasing the weight makes it less likely to be travelled to, decreasing more likely).

Usage

// query a node in the graph and increase the weight property
if let node = graph.node(atGridPosition: coord) as? SKTiledGraphNode {
   node.weight = 25.0
}

Initialization

  • Initialize the node with a weight parameter.

    Declaration

    Swift

    public init(gridPosition: simd_int2, weight: Float = 1.0)

    Parameters

    gridPosition

    vector simd_int2 coordinates.

    weight

    node weight.

  • Instantiate the node with a decoder instance.

    Declaration

    Swift

    required public init?(coder aDecoder: NSCoder)

    Parameters

    aDecoder

    decoder.

Pathfinding

  • The GKGridGraphNode.cost method is used in the GKGridGraphNode.findPathToNode method. Returns the cost (lower is better) for each node in the possible nodes.

    Declaration

    Swift

    public override func cost(to node: GKGraphNode) -> Float

    Parameters

    node

    node to estimate from.

    Return Value

    cost to travel to the given node.

  • Returns the heuristic cost to node.

    Declaration

    Swift

    public override func estimatedCost(to node: GKGraphNode) -> Float

    Parameters

    node

    target graph node.

    Return Value

    heuristic cost to node.

  • Parse the tile data’s properties value.

    Declaration

    Swift

    public func parseProperties(completion: (() -> Void)?)

    Parameters

    completion

    optional completion function.