NavigationPolygon.xml 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <class name="NavigationPolygon" inherits="Resource" version="4.0">
  3. <brief_description>
  4. A node that has methods to draw outlines or use indices of vertices to create navigation polygons.
  5. </brief_description>
  6. <description>
  7. There are two ways to create polygons. Either by using the [method add_outline] method, or using the [method add_polygon] method.
  8. Using [method add_outline]:
  9. [codeblocks]
  10. [gdscript]
  11. var polygon = NavigationPolygon.new()
  12. var outline = PackedVector2Array([Vector2(0, 0), Vector2(0, 50), Vector2(50, 50), Vector2(50, 0)])
  13. polygon.add_outline(outline)
  14. polygon.make_polygons_from_outlines()
  15. $NavigationRegion2D.navpoly = polygon
  16. [/gdscript]
  17. [csharp]
  18. var polygon = new NavigationPolygon();
  19. var outline = new Vector2[] { new Vector2(0, 0), new Vector2(0, 50), new Vector2(50, 50), new Vector2(50, 0) };
  20. polygon.AddOutline(outline);
  21. polygon.MakePolygonsFromOutlines();
  22. GetNode&lt;NavigationRegion2D&gt;("NavigationRegion2D").Navpoly = polygon;
  23. [/csharp]
  24. [/codeblocks]
  25. Using [method add_polygon] and indices of the vertices array.
  26. [codeblocks]
  27. [gdscript]
  28. var polygon = NavigationPolygon.new()
  29. var vertices = PackedVector2Array([Vector2(0, 0), Vector2(0, 50), Vector2(50, 50), Vector2(50, 0)])
  30. polygon.vertices = vertices
  31. var indices = PackedInt32Array(0, 3, 1)
  32. polygon.add_polygon(indices)
  33. $NavigationRegion2D.navpoly = polygon
  34. [/gdscript]
  35. [csharp]
  36. var polygon = new NavigationPolygon();
  37. var vertices = new Vector2[] { new Vector2(0, 0), new Vector2(0, 50), new Vector2(50, 50), new Vector2(50, 0) };
  38. polygon.Vertices = vertices;
  39. var indices = new int[] { 0, 3, 1 };
  40. polygon.AddPolygon(indices);
  41. GetNode&lt;NavigationRegion2D&gt;("NavigationRegion2D").Navpoly = polygon;
  42. [/csharp]
  43. [/codeblocks]
  44. </description>
  45. <tutorials>
  46. <link title="2D Navigation Demo">https://godotengine.org/asset-library/asset/117</link>
  47. </tutorials>
  48. <methods>
  49. <method name="add_outline">
  50. <return type="void" />
  51. <argument index="0" name="outline" type="PackedVector2Array" />
  52. <description>
  53. Appends a [PackedVector2Array] that contains the vertices of an outline to the internal array that contains all the outlines. You have to call [method make_polygons_from_outlines] in order for this array to be converted to polygons that the engine will use.
  54. </description>
  55. </method>
  56. <method name="add_outline_at_index">
  57. <return type="void" />
  58. <argument index="0" name="outline" type="PackedVector2Array" />
  59. <argument index="1" name="index" type="int" />
  60. <description>
  61. Adds a [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 [method make_polygons_from_outlines] in order for this array to be converted to polygons that the engine will use.
  62. </description>
  63. </method>
  64. <method name="add_polygon">
  65. <return type="void" />
  66. <argument index="0" name="polygon" type="PackedInt32Array" />
  67. <description>
  68. Adds a polygon using the indices of the vertices you get when calling [method get_vertices].
  69. </description>
  70. </method>
  71. <method name="clear_outlines">
  72. <return type="void" />
  73. <description>
  74. Clears the array of the outlines, but it doesn't clear the vertices and the polygons that were created by them.
  75. </description>
  76. </method>
  77. <method name="clear_polygons">
  78. <return type="void" />
  79. <description>
  80. Clears the array of polygons, but it doesn't clear the array of outlines and vertices.
  81. </description>
  82. </method>
  83. <method name="get_outline" qualifiers="const">
  84. <return type="PackedVector2Array" />
  85. <argument index="0" name="idx" type="int" />
  86. <description>
  87. Returns a [PackedVector2Array] containing the vertices of an outline that was created in the editor or by script.
  88. </description>
  89. </method>
  90. <method name="get_outline_count" qualifiers="const">
  91. <return type="int" />
  92. <description>
  93. Returns the number of outlines that were created in the editor or by script.
  94. </description>
  95. </method>
  96. <method name="get_polygon">
  97. <return type="PackedInt32Array" />
  98. <argument index="0" name="idx" type="int" />
  99. <description>
  100. Returns a [PackedInt32Array] containing the indices of the vertices of a created polygon.
  101. </description>
  102. </method>
  103. <method name="get_polygon_count" qualifiers="const">
  104. <return type="int" />
  105. <description>
  106. Returns the count of all polygons.
  107. </description>
  108. </method>
  109. <method name="get_vertices" qualifiers="const">
  110. <return type="PackedVector2Array" />
  111. <description>
  112. Returns a [PackedVector2Array] containing all the vertices being used to create the polygons.
  113. </description>
  114. </method>
  115. <method name="make_polygons_from_outlines">
  116. <return type="void" />
  117. <description>
  118. Creates polygons from the outlines added in the editor or by script.
  119. </description>
  120. </method>
  121. <method name="remove_outline">
  122. <return type="void" />
  123. <argument index="0" name="idx" type="int" />
  124. <description>
  125. Removes an outline created in the editor or by script. You have to call [method make_polygons_from_outlines] for the polygons to update.
  126. </description>
  127. </method>
  128. <method name="set_outline">
  129. <return type="void" />
  130. <argument index="0" name="idx" type="int" />
  131. <argument index="1" name="outline" type="PackedVector2Array" />
  132. <description>
  133. Changes an outline created in the editor or by script. You have to call [method make_polygons_from_outlines] for the polygons to update.
  134. </description>
  135. </method>
  136. <method name="set_vertices">
  137. <return type="void" />
  138. <argument index="0" name="vertices" type="PackedVector2Array" />
  139. <description>
  140. Sets the vertices that can be then indexed to create polygons with the [method add_polygon] method.
  141. </description>
  142. </method>
  143. </methods>
  144. </class>