class_navigationpolygon.rst 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. :github_url: hide
  2. .. Generated automatically by doc/tools/make_rst.py in Godot's source tree.
  3. .. DO NOT EDIT THIS FILE, but the NavigationPolygon.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_NavigationPolygon:
  6. NavigationPolygon
  7. =================
  8. **Inherits:** :ref:`Resource<class_Resource>` **<** :ref:`RefCounted<class_RefCounted>` **<** :ref:`Object<class_Object>`
  9. A node that has methods to draw outlines or use indices of vertices to create navigation polygons.
  10. Description
  11. -----------
  12. 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.
  13. Using :ref:`add_outline<class_NavigationPolygon_method_add_outline>`:
  14. .. tabs::
  15. .. code-tab:: gdscript
  16. var polygon = NavigationPolygon.new()
  17. var outline = PackedVector2Array([Vector2(0, 0), Vector2(0, 50), Vector2(50, 50), Vector2(50, 0)])
  18. polygon.add_outline(outline)
  19. polygon.make_polygons_from_outlines()
  20. $NavigationRegion2D.navpoly = polygon
  21. .. code-tab:: csharp
  22. var polygon = new NavigationPolygon();
  23. var outline = new Vector2[] { new Vector2(0, 0), new Vector2(0, 50), new Vector2(50, 50), new Vector2(50, 0) };
  24. polygon.AddOutline(outline);
  25. polygon.MakePolygonsFromOutlines();
  26. GetNode<NavigationRegion2D>("NavigationRegion2D").Navpoly = polygon;
  27. Using :ref:`add_polygon<class_NavigationPolygon_method_add_polygon>` and indices of the vertices array.
  28. .. tabs::
  29. .. code-tab:: gdscript
  30. var polygon = NavigationPolygon.new()
  31. var vertices = PackedVector2Array([Vector2(0, 0), Vector2(0, 50), Vector2(50, 50), Vector2(50, 0)])
  32. polygon.vertices = vertices
  33. var indices = PackedInt32Array([0, 1, 2, 3])
  34. polygon.add_polygon(indices)
  35. $NavigationRegion2D.navpoly = polygon
  36. .. code-tab:: csharp
  37. var polygon = new NavigationPolygon();
  38. var vertices = new Vector2[] { new Vector2(0, 0), new Vector2(0, 50), new Vector2(50, 50), new Vector2(50, 0) };
  39. polygon.Vertices = vertices;
  40. var indices = new int[] { 0, 1, 2, 3 };
  41. polygon.AddPolygon(indices);
  42. GetNode<NavigationRegion2D>("NavigationRegion2D").Navpoly = polygon;
  43. Tutorials
  44. ---------
  45. - `2D Navigation Demo <https://godotengine.org/asset-library/asset/117>`__
  46. Methods
  47. -------
  48. +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  49. | void | :ref:`add_outline<class_NavigationPolygon_method_add_outline>` **(** :ref:`PackedVector2Array<class_PackedVector2Array>` outline **)** |
  50. +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  51. | void | :ref:`add_outline_at_index<class_NavigationPolygon_method_add_outline_at_index>` **(** :ref:`PackedVector2Array<class_PackedVector2Array>` outline, :ref:`int<class_int>` index **)** |
  52. +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  53. | void | :ref:`add_polygon<class_NavigationPolygon_method_add_polygon>` **(** :ref:`PackedInt32Array<class_PackedInt32Array>` polygon **)** |
  54. +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  55. | void | :ref:`clear_outlines<class_NavigationPolygon_method_clear_outlines>` **(** **)** |
  56. +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  57. | void | :ref:`clear_polygons<class_NavigationPolygon_method_clear_polygons>` **(** **)** |
  58. +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  59. | :ref:`PackedVector2Array<class_PackedVector2Array>` | :ref:`get_outline<class_NavigationPolygon_method_get_outline>` **(** :ref:`int<class_int>` idx **)** |const| |
  60. +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  61. | :ref:`int<class_int>` | :ref:`get_outline_count<class_NavigationPolygon_method_get_outline_count>` **(** **)** |const| |
  62. +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  63. | :ref:`PackedInt32Array<class_PackedInt32Array>` | :ref:`get_polygon<class_NavigationPolygon_method_get_polygon>` **(** :ref:`int<class_int>` idx **)** |
  64. +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  65. | :ref:`int<class_int>` | :ref:`get_polygon_count<class_NavigationPolygon_method_get_polygon_count>` **(** **)** |const| |
  66. +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  67. | :ref:`PackedVector2Array<class_PackedVector2Array>` | :ref:`get_vertices<class_NavigationPolygon_method_get_vertices>` **(** **)** |const| |
  68. +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  69. | void | :ref:`make_polygons_from_outlines<class_NavigationPolygon_method_make_polygons_from_outlines>` **(** **)** |
  70. +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  71. | void | :ref:`remove_outline<class_NavigationPolygon_method_remove_outline>` **(** :ref:`int<class_int>` idx **)** |
  72. +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  73. | void | :ref:`set_outline<class_NavigationPolygon_method_set_outline>` **(** :ref:`int<class_int>` idx, :ref:`PackedVector2Array<class_PackedVector2Array>` outline **)** |
  74. +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  75. | void | :ref:`set_vertices<class_NavigationPolygon_method_set_vertices>` **(** :ref:`PackedVector2Array<class_PackedVector2Array>` vertices **)** |
  76. +-----------------------------------------------------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  77. Method Descriptions
  78. -------------------
  79. .. _class_NavigationPolygon_method_add_outline:
  80. - void **add_outline** **(** :ref:`PackedVector2Array<class_PackedVector2Array>` outline **)**
  81. 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.
  82. ----
  83. .. _class_NavigationPolygon_method_add_outline_at_index:
  84. - void **add_outline_at_index** **(** :ref:`PackedVector2Array<class_PackedVector2Array>` outline, :ref:`int<class_int>` index **)**
  85. 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.
  86. ----
  87. .. _class_NavigationPolygon_method_add_polygon:
  88. - void **add_polygon** **(** :ref:`PackedInt32Array<class_PackedInt32Array>` polygon **)**
  89. Adds a polygon using the indices of the vertices you get when calling :ref:`get_vertices<class_NavigationPolygon_method_get_vertices>`.
  90. ----
  91. .. _class_NavigationPolygon_method_clear_outlines:
  92. - void **clear_outlines** **(** **)**
  93. Clears the array of the outlines, but it doesn't clear the vertices and the polygons that were created by them.
  94. ----
  95. .. _class_NavigationPolygon_method_clear_polygons:
  96. - void **clear_polygons** **(** **)**
  97. Clears the array of polygons, but it doesn't clear the array of outlines and vertices.
  98. ----
  99. .. _class_NavigationPolygon_method_get_outline:
  100. - :ref:`PackedVector2Array<class_PackedVector2Array>` **get_outline** **(** :ref:`int<class_int>` idx **)** |const|
  101. Returns a :ref:`PackedVector2Array<class_PackedVector2Array>` containing the vertices of an outline that was created in the editor or by script.
  102. ----
  103. .. _class_NavigationPolygon_method_get_outline_count:
  104. - :ref:`int<class_int>` **get_outline_count** **(** **)** |const|
  105. Returns the number of outlines that were created in the editor or by script.
  106. ----
  107. .. _class_NavigationPolygon_method_get_polygon:
  108. - :ref:`PackedInt32Array<class_PackedInt32Array>` **get_polygon** **(** :ref:`int<class_int>` idx **)**
  109. Returns a :ref:`PackedInt32Array<class_PackedInt32Array>` containing the indices of the vertices of a created polygon.
  110. ----
  111. .. _class_NavigationPolygon_method_get_polygon_count:
  112. - :ref:`int<class_int>` **get_polygon_count** **(** **)** |const|
  113. Returns the count of all polygons.
  114. ----
  115. .. _class_NavigationPolygon_method_get_vertices:
  116. - :ref:`PackedVector2Array<class_PackedVector2Array>` **get_vertices** **(** **)** |const|
  117. Returns a :ref:`PackedVector2Array<class_PackedVector2Array>` containing all the vertices being used to create the polygons.
  118. ----
  119. .. _class_NavigationPolygon_method_make_polygons_from_outlines:
  120. - void **make_polygons_from_outlines** **(** **)**
  121. Creates polygons from the outlines added in the editor or by script.
  122. ----
  123. .. _class_NavigationPolygon_method_remove_outline:
  124. - void **remove_outline** **(** :ref:`int<class_int>` idx **)**
  125. 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.
  126. ----
  127. .. _class_NavigationPolygon_method_set_outline:
  128. - void **set_outline** **(** :ref:`int<class_int>` idx, :ref:`PackedVector2Array<class_PackedVector2Array>` outline **)**
  129. 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.
  130. ----
  131. .. _class_NavigationPolygon_method_set_vertices:
  132. - void **set_vertices** **(** :ref:`PackedVector2Array<class_PackedVector2Array>` vertices **)**
  133. Sets the vertices that can be then indexed to create polygons with the :ref:`add_polygon<class_NavigationPolygon_method_add_polygon>` method.
  134. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  135. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  136. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  137. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  138. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  139. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`