> For the complete documentation index, see [llms.txt](https://docs.flatredball.com/flatredball/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.flatredball.com/flatredball/api/flatredball/ai/pathfinding-2/flatredball-ai-pathfinding-tilenodenetwork/addandlinktilednode.md).

# AddAndLinkTiledNode

### Introduction

AddAndLinkTiledNode adds a new PositionedNode at the argument X, Y index at the argument DirectionType, or using the default DirectionType specified in the constructor if one isn't specified. This method uses indexes, where 0,0 is the bottom left of the TileNodeNetwork. Each index represents one tile, so if your TileNodeNetwork has a tile size of 16, then an X value of 1 would translate to 16 pixels further to the right than an X index of 0.

### Code Example - Adding nodes manually

The following code adds a few nodes to a TileNodeNetwork using X,Y indexes.

```lang:c#
void CustomInitialize()
{
    var left = -150;
    var bottom = -150;
    var gridSize = 32;
    var numberOfTilesWide = 30;
    var numberOfTilesTall = 30;

    var tileNodeNetwork = new TileNodeNetwork(left, bottom,
        gridSize, numberOfTilesWide, numberOfTilesTall, DirectionalType.Four);

    // add nodes at some positions at index X, Y
    // Note this is index and not world positions, 
    // so 0,0 will always be the bottom-left location
    // of the node network regardless of its actual world
    // position
    tileNodeNetwork.AddAndLinkTiledNode(0, 0);
    tileNodeNetwork.AddAndLinkTiledNode(1, 0);
    tileNodeNetwork.AddAndLinkTiledNode(2, 0);
    tileNodeNetwork.AddAndLinkTiledNode(3, 0);


    tileNodeNetwork.AddAndLinkTiledNode(2, 1);
    tileNodeNetwork.AddAndLinkTiledNode(3, 1);
    tileNodeNetwork.AddAndLinkTiledNode(4, 1);
    tileNodeNetwork.AddAndLinkTiledNode(5, 1);


    tileNodeNetwork.AddAndLinkTiledNode(2, 2);
    tileNodeNetwork.AddAndLinkTiledNode(2, 3);
    tileNodeNetwork.AddAndLinkTiledNode(2, 4);
    tileNodeNetwork.AddAndLinkTiledNode(2, 5);

    // So we can see the node network changes
    tileNodeNetwork.Visible = true;
}
```

![](https://951240982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fye9Ufg3vzJxwX5Hk%2Fuploads%2Fgit-blob-959a3d567f7bfeb9d97c4d73c7d2170f75e24c8a%2F2019-08-img_5d63e7723e433.png?alt=media)

### Code Example - Adding Nodes with the Cursor

The following code can be used to add nodes with the cursor when the PrimaryDown value is true (left mouse button). The following code could be added to CustomActivity of a Screen which has access to a TileNodeNetwork.

```
var cursor = GuiManager.Cursor;

if(cursor.PrimaryDown)
{
    TileNodeNetwork.WorldToIndex(cursor.WorldX, cursor.WorldY, out int xIndex, out int yIndex);

    var nodeAtPoint = TileNodeNetwork.TiledNodeAt(xIndex, yIndex);
    if(nodeAtPoint == null)
    {
        TileNodeNetwork.AddAndLinkTiledNode(xIndex, yIndex);
        TileNodeNetwork.UpdateShapes();
    }
}
```

<figure><img src="https://951240982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fye9Ufg3vzJxwX5Hk%2Fuploads%2Fgit-blob-349fe0b833a624e6a575eb26336f374b5aa56540%2F2019-08-j5VMYNqadR.gif?alt=media" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.flatredball.com/flatredball/api/flatredball/ai/pathfinding-2/flatredball-ai-pathfinding-tilenodenetwork/addandlinktilednode.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
