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