NodeNetwork
Introduction
Creating a NodeNetwork in Code
using FlatRedBall.AI.Pathfinding;
using FlatRedBall.Input;NodeNetwork nodeNetwork;
Sprite sprite;
List<PositionedNode> nodePath; // Instantiate the NodeNetwork.
nodeNetwork = new NodeNetwork();
// Create the 4 nodes.
PositionedNode node = nodeNetwork.AddNode();
node.Position = new Vector3(-150, 150, 0); // top left
node = nodeNetwork.AddNode();
node.Position = new Vector3(150, 150, 0); // top right
node = nodeNetwork.AddNode();
node.Position = new Vector3(150, -150, 0); // bottom right
node = nodeNetwork.AddNode();
node.Position = new Vector3(-150, -150, 0); // bottom left
// Link the nodes together.
// LinkTo creates two links - one to and one from.
float linkCost = 1;
nodeNetwork.Nodes[0].LinkTo(nodeNetwork.Nodes[1], linkCost);
nodeNetwork.Nodes[1].LinkTo(nodeNetwork.Nodes[2], linkCost);
nodeNetwork.Nodes[2].LinkTo(nodeNetwork.Nodes[3], linkCost);
nodeNetwork.Nodes[3].LinkTo(nodeNetwork.Nodes[0], linkCost);
// Make the NodeNetwork visible. Usually only used for debugging
// and development.
nodeNetwork.Visible = true;
// Create the Sprite used to move around the NodeNetwork
sprite = SpriteManager.AddSprite(RedBallTexture);
sprite.TextureScale = 1;
Loading a NodeNetwork From .nntx

Last updated
Was this helpful?