SKTiledGraphNode

public class SKTiledGraphNode : GKGridGraphNode, SKTiledObject

Overview

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
}

Init

  • Initialize the node with a weight parameter.

    Declaration

    Swift

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

    Parameters

    gridPosition

    int2 vector int2 coordinates.

    weight

    Float node weight.

    Return Value

    SKTiledGraphNode node instance.

Pathfinding

  • ▶︎cost(to:)

    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

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

    Parameters

    node

    GKGraphNode node to estimate from.

    Return Value

    Float cost to travel to the given node.

  • Returns the heuristic cost to node.

    Declaration

    Swift

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

    Parameters

    node

    GKGraphNode target graph node.

    Return Value

    Float heuristic cost to node.

  • Parse the tile data’s properties value.

    Declaration

    Swift

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

    Parameters

    completion

    () -> Void)? optional completion function.