AddAndLinkTiledNodeWorld
Introduction
Code Example: Adding Nodes by Clicking
// Define the TileNodeNetwork at class scope
// so we can access it in both CustomInitialize
// and CustomActivity
TileNodeNetwork tileNodeNetwork;
void CustomInitialize()
{
var left = -200;
var bottom = -200;
var gridSize = 32;
var numberOfTilesWide = 40;
var numberOfTilesTall = 40;
tileNodeNetwork = new TileNodeNetwork(left, bottom,
gridSize, numberOfTilesWide, numberOfTilesTall, DirectionalType.Four);
// So we can see the node network changes
tileNodeNetwork.Visible = true;
// So we can see the cursor
FlatRedBallServices.Game.IsMouseVisible = true;
}
void CustomActivity(bool firstTimeCalled)
{
var cursor = FlatRedBall.Gui.GuiManager.Cursor;
if(cursor.PrimaryClick)
{
var worldX = cursor.WorldXAt(0);
var worldY = cursor.WorldYAt(0);
// See if there is an existing node there:
var existingNode = tileNodeNetwork.TiledNodeAtWorld(worldX, worldY);
if(existingNode == null)
{
tileNodeNetwork.AddAndLinkTiledNodeWorld(worldX, worldY);
// So we can see the newly-added shapes
tileNodeNetwork.UpdateShapes();
}
}
}
Last updated
Was this helpful?