Skip to content

Latest commit

 

History

History
187 lines (115 loc) · 12.4 KB

class_navigationpolygon.rst

File metadata and controls

187 lines (115 loc) · 12.4 KB
github_url:hide

NavigationPolygon

Inherits: :ref:`Resource<class_Resource>` < :ref:`Reference<class_Reference>` < :ref:`Object<class_Object>`

A node that has methods to draw outlines or use indices of vertices to create navigation polygons.

Description

There are two ways to create polygons. Either by using the :ref:`add_outline<class_NavigationPolygon_method_add_outline>` method, or using the :ref:`add_polygon<class_NavigationPolygon_method_add_polygon>` method.

Using :ref:`add_outline<class_NavigationPolygon_method_add_outline>`:

var polygon = NavigationPolygon.new()
var outline = PackedVector2Array([Vector2(0, 0), Vector2(0, 50), Vector2(50, 50), Vector2(50, 0)])
polygon.add_outline(outline)
polygon.make_polygons_from_outlines()
$NavigationRegion2D.navpoly = polygon

Using :ref:`add_polygon<class_NavigationPolygon_method_add_polygon>` and indices of the vertices array.

var polygon = NavigationPolygon.new()
var vertices = PackedVector2Array([Vector2(0, 0), Vector2(0, 50), Vector2(50, 50), Vector2(50, 0)])
polygon.set_vertices(vertices)
var indices = PackedInt32Array(0, 3, 1)
polygon.add_polygon(indices)
$NavigationRegion2D.navpoly = polygon

Methods

void :ref:`add_outline<class_NavigationPolygon_method_add_outline>` ( :ref:`PackedVector2Array<class_PackedVector2Array>` outline )
void :ref:`add_outline_at_index<class_NavigationPolygon_method_add_outline_at_index>` ( :ref:`PackedVector2Array<class_PackedVector2Array>` outline, :ref:`int<class_int>` index )
void :ref:`add_polygon<class_NavigationPolygon_method_add_polygon>` ( :ref:`PackedInt32Array<class_PackedInt32Array>` polygon )
void :ref:`clear_outlines<class_NavigationPolygon_method_clear_outlines>` ( )
void :ref:`clear_polygons<class_NavigationPolygon_method_clear_polygons>` ( )
:ref:`PackedVector2Array<class_PackedVector2Array>` :ref:`get_outline<class_NavigationPolygon_method_get_outline>` ( :ref:`int<class_int>` idx ) const
:ref:`int<class_int>` :ref:`get_outline_count<class_NavigationPolygon_method_get_outline_count>` ( ) const
:ref:`PackedInt32Array<class_PackedInt32Array>` :ref:`get_polygon<class_NavigationPolygon_method_get_polygon>` ( :ref:`int<class_int>` idx )
:ref:`int<class_int>` :ref:`get_polygon_count<class_NavigationPolygon_method_get_polygon_count>` ( ) const
:ref:`PackedVector2Array<class_PackedVector2Array>` :ref:`get_vertices<class_NavigationPolygon_method_get_vertices>` ( ) const
void :ref:`make_polygons_from_outlines<class_NavigationPolygon_method_make_polygons_from_outlines>` ( )
void :ref:`remove_outline<class_NavigationPolygon_method_remove_outline>` ( :ref:`int<class_int>` idx )
void :ref:`set_outline<class_NavigationPolygon_method_set_outline>` ( :ref:`int<class_int>` idx, :ref:`PackedVector2Array<class_PackedVector2Array>` outline )
void :ref:`set_vertices<class_NavigationPolygon_method_set_vertices>` ( :ref:`PackedVector2Array<class_PackedVector2Array>` vertices )

Method Descriptions

Appends a :ref:`PackedVector2Array<class_PackedVector2Array>` that contains the vertices of an outline to the internal array that contains all the outlines. You have to call :ref:`make_polygons_from_outlines<class_NavigationPolygon_method_make_polygons_from_outlines>` in order for this array to be converted to polygons that the engine will use.


Adds a :ref:`PackedVector2Array<class_PackedVector2Array>` that contains the vertices of an outline to the internal array that contains all the outlines at a fixed position. You have to call :ref:`make_polygons_from_outlines<class_NavigationPolygon_method_make_polygons_from_outlines>` in order for this array to be converted to polygons that the engine will use.


Adds a polygon using the indices of the vertices you get when calling :ref:`get_vertices<class_NavigationPolygon_method_get_vertices>`.


  • void clear_outlines ( )

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


  • void clear_polygons ( )

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


Returns a :ref:`PackedVector2Array<class_PackedVector2Array>` containing the vertices of an outline that was created in the editor or by script.


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


Returns a :ref:`PackedInt32Array<class_PackedInt32Array>` containing the indices of the vertices of a created polygon.


Returns the count of all polygons.


Returns a :ref:`PackedVector2Array<class_PackedVector2Array>` containing all the vertices being used to create the polygons.


  • void make_polygons_from_outlines ( )

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


Removes an outline created in the editor or by script. You have to call :ref:`make_polygons_from_outlines<class_NavigationPolygon_method_make_polygons_from_outlines>` for the polygons to update.


Changes an outline created in the editor or by script. You have to call :ref:`make_polygons_from_outlines<class_NavigationPolygon_method_make_polygons_from_outlines>` for the polygons to update.


Sets the vertices that can be then indexed to create polygons with the :ref:`add_polygon<class_NavigationPolygon_method_add_polygon>` method.