A node that has methods to draw outlines or use indices of vertices to create navigation polygons.
    public class NavigationPolygon : Resource

There are two ways to create polygons. Either by using the AddOutline(Godot.Vector2[]) method or using the AddPolygon(int[]) method.

Using AddOutline(Godot.Vector2[]):

[codeblock]

var polygon = NavigationPolygon.new()

var outline = PoolVector2Array([Vector2(0, 0), Vector2(0, 50), Vector2(50, 50), Vector2(50, 0)])

polygon.add_outline(outline)

polygon.make_polygons_from_outlines()

$NavigationPolygonInstance.navpoly = polygon

[/codeblock]

Using AddPolygon(int[]) and indices of the vertices array.

[codeblock]

var polygon = NavigationPolygon.new()

var vertices = PoolVector2Array([Vector2(0, 0), Vector2(0, 50), Vector2(50, 50), Vector2(50, 0)])

polygon.set_vertices(vertices)

var indices = PoolIntArray(0, 3, 1)

polygon.add_polygon(indices)

$NavigationPolygonInstance.navpoly = polygon

[/codeblock]

Inheritance Chain

Constructors

    public NavigationPolygon()

Properties

    public Collections.Array Outlines { get; set; }

    public Collections.Array Polygons { get; set; }

    public Vector2[] Vertices { get; set; }

Methods

    public void AddOutline(Vector2[] outline)

Appends a PoolVector2Array that contains the vertices of an outline to the internal array that contains all the outlines. You have to call MakePolygonsFromOutlines() in order for this array to be converted to polygons that the engine will use.

    public void AddOutlineAtIndex(Vector2[] outline, int index)

Adds a PoolVector2Array that contains the vertices of an outline to the internal array that contains all the outlines at a fixed position. You have to call MakePolygonsFromOutlines() in order for this array to be converted to polygons that the engine will use.

    public void AddPolygon(int[] polygon)

Adds a polygon using the indices of the vertices you get when calling GetVertices().

    public void ClearOutlines()

Clears the array of the outlines, but it doesn’t clear the vertices and the polygons that were created by them.

    public void ClearPolygons()

Clears the array of polygons, but it doesn’t clear the array of outlines and vertices.

    public Vector2[] GetOutline(int idx)

Returns a PoolVector2Array containing the vertices of an outline that was created in the editor or by script.

    public int GetOutlineCount()

Returns the number of outlines that were created in the editor or by script.

    public int[] GetPolygon(int idx)

Returns a PoolIntArray containing the indices of the vertices of a created polygon.

    public int GetPolygonCount()

Returns the count of all polygons.

    public Vector2[] GetVertices()

Returns a PoolVector2Array containing all the vertices being used to create the polygons.

    public void MakePolygonsFromOutlines()

Creates polygons from the outlines added in the editor or by script.

    public void RemoveOutline(int idx)

Removes an outline created in the editor or by script. You have to call MakePolygonsFromOutlines() for the polygons to update.

    public void SetOutline(int idx, Vector2[] outline)

Changes an outline created in the editor or by script. You have to call MakePolygonsFromOutlines() for the polygons to update.

    public void SetVertices(Vector2[] vertices)

Sets the vertices that can be then indexed to create polygons with the AddPolygon(int[]) method.

Tags: