class_navigationpolygon.rst 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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:`Reference<class_Reference>` **<** :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. ::
  15. var polygon = NavigationPolygon.new()
  16. var outline = PoolVector2Array([Vector2(0, 0), Vector2(0, 50), Vector2(50, 50), Vector2(50, 0)])
  17. polygon.add_outline(outline)
  18. polygon.make_polygons_from_outlines()
  19. $NavigationPolygonInstance.navpoly = polygon
  20. Using :ref:`add_polygon<class_NavigationPolygon_method_add_polygon>` and indices of the vertices array.
  21. ::
  22. var polygon = NavigationPolygon.new()
  23. var vertices = PoolVector2Array([Vector2(0, 0), Vector2(0, 50), Vector2(50, 50), Vector2(50, 0)])
  24. polygon.set_vertices(vertices)
  25. var indices = PoolIntArray([0, 1, 2, 3])
  26. polygon.add_polygon(indices)
  27. $NavigationPolygonInstance.navpoly = polygon
  28. Tutorials
  29. ---------
  30. - `2D Navigation Demo <https://godotengine.org/asset-library/asset/117>`__
  31. Methods
  32. -------
  33. +-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  34. | void | :ref:`add_outline<class_NavigationPolygon_method_add_outline>` **(** :ref:`PoolVector2Array<class_PoolVector2Array>` outline **)** |
  35. +-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  36. | void | :ref:`add_outline_at_index<class_NavigationPolygon_method_add_outline_at_index>` **(** :ref:`PoolVector2Array<class_PoolVector2Array>` outline, :ref:`int<class_int>` index **)** |
  37. +-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  38. | void | :ref:`add_polygon<class_NavigationPolygon_method_add_polygon>` **(** :ref:`PoolIntArray<class_PoolIntArray>` polygon **)** |
  39. +-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  40. | void | :ref:`clear_outlines<class_NavigationPolygon_method_clear_outlines>` **(** **)** |
  41. +-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  42. | void | :ref:`clear_polygons<class_NavigationPolygon_method_clear_polygons>` **(** **)** |
  43. +-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  44. | :ref:`PoolVector2Array<class_PoolVector2Array>` | :ref:`get_outline<class_NavigationPolygon_method_get_outline>` **(** :ref:`int<class_int>` idx **)** |const| |
  45. +-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  46. | :ref:`int<class_int>` | :ref:`get_outline_count<class_NavigationPolygon_method_get_outline_count>` **(** **)** |const| |
  47. +-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  48. | :ref:`PoolIntArray<class_PoolIntArray>` | :ref:`get_polygon<class_NavigationPolygon_method_get_polygon>` **(** :ref:`int<class_int>` idx **)** |
  49. +-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  50. | :ref:`int<class_int>` | :ref:`get_polygon_count<class_NavigationPolygon_method_get_polygon_count>` **(** **)** |const| |
  51. +-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  52. | :ref:`PoolVector2Array<class_PoolVector2Array>` | :ref:`get_vertices<class_NavigationPolygon_method_get_vertices>` **(** **)** |const| |
  53. +-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  54. | void | :ref:`make_polygons_from_outlines<class_NavigationPolygon_method_make_polygons_from_outlines>` **(** **)** |
  55. +-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  56. | void | :ref:`remove_outline<class_NavigationPolygon_method_remove_outline>` **(** :ref:`int<class_int>` idx **)** |
  57. +-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  58. | void | :ref:`set_outline<class_NavigationPolygon_method_set_outline>` **(** :ref:`int<class_int>` idx, :ref:`PoolVector2Array<class_PoolVector2Array>` outline **)** |
  59. +-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  60. | void | :ref:`set_vertices<class_NavigationPolygon_method_set_vertices>` **(** :ref:`PoolVector2Array<class_PoolVector2Array>` vertices **)** |
  61. +-------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  62. Method Descriptions
  63. -------------------
  64. .. _class_NavigationPolygon_method_add_outline:
  65. - void **add_outline** **(** :ref:`PoolVector2Array<class_PoolVector2Array>` outline **)**
  66. Appends a :ref:`PoolVector2Array<class_PoolVector2Array>` 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.
  67. ----
  68. .. _class_NavigationPolygon_method_add_outline_at_index:
  69. - void **add_outline_at_index** **(** :ref:`PoolVector2Array<class_PoolVector2Array>` outline, :ref:`int<class_int>` index **)**
  70. Adds a :ref:`PoolVector2Array<class_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 :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.
  71. ----
  72. .. _class_NavigationPolygon_method_add_polygon:
  73. - void **add_polygon** **(** :ref:`PoolIntArray<class_PoolIntArray>` polygon **)**
  74. Adds a polygon using the indices of the vertices you get when calling :ref:`get_vertices<class_NavigationPolygon_method_get_vertices>`.
  75. ----
  76. .. _class_NavigationPolygon_method_clear_outlines:
  77. - void **clear_outlines** **(** **)**
  78. Clears the array of the outlines, but it doesn't clear the vertices and the polygons that were created by them.
  79. ----
  80. .. _class_NavigationPolygon_method_clear_polygons:
  81. - void **clear_polygons** **(** **)**
  82. Clears the array of polygons, but it doesn't clear the array of outlines and vertices.
  83. ----
  84. .. _class_NavigationPolygon_method_get_outline:
  85. - :ref:`PoolVector2Array<class_PoolVector2Array>` **get_outline** **(** :ref:`int<class_int>` idx **)** |const|
  86. Returns a :ref:`PoolVector2Array<class_PoolVector2Array>` containing the vertices of an outline that was created in the editor or by script.
  87. ----
  88. .. _class_NavigationPolygon_method_get_outline_count:
  89. - :ref:`int<class_int>` **get_outline_count** **(** **)** |const|
  90. Returns the number of outlines that were created in the editor or by script.
  91. ----
  92. .. _class_NavigationPolygon_method_get_polygon:
  93. - :ref:`PoolIntArray<class_PoolIntArray>` **get_polygon** **(** :ref:`int<class_int>` idx **)**
  94. Returns a :ref:`PoolIntArray<class_PoolIntArray>` containing the indices of the vertices of a created polygon.
  95. ----
  96. .. _class_NavigationPolygon_method_get_polygon_count:
  97. - :ref:`int<class_int>` **get_polygon_count** **(** **)** |const|
  98. Returns the count of all polygons.
  99. ----
  100. .. _class_NavigationPolygon_method_get_vertices:
  101. - :ref:`PoolVector2Array<class_PoolVector2Array>` **get_vertices** **(** **)** |const|
  102. Returns a :ref:`PoolVector2Array<class_PoolVector2Array>` containing all the vertices being used to create the polygons.
  103. ----
  104. .. _class_NavigationPolygon_method_make_polygons_from_outlines:
  105. - void **make_polygons_from_outlines** **(** **)**
  106. Creates polygons from the outlines added in the editor or by script.
  107. ----
  108. .. _class_NavigationPolygon_method_remove_outline:
  109. - void **remove_outline** **(** :ref:`int<class_int>` idx **)**
  110. 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.
  111. ----
  112. .. _class_NavigationPolygon_method_set_outline:
  113. - void **set_outline** **(** :ref:`int<class_int>` idx, :ref:`PoolVector2Array<class_PoolVector2Array>` outline **)**
  114. 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.
  115. ----
  116. .. _class_NavigationPolygon_method_set_vertices:
  117. - void **set_vertices** **(** :ref:`PoolVector2Array<class_PoolVector2Array>` vertices **)**
  118. Sets the vertices that can be then indexed to create polygons with the :ref:`add_polygon<class_NavigationPolygon_method_add_polygon>` method.
  119. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  120. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  121. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`