There are two ways to create polygons. Either by using the godot.NavigationPolygon.addOutline
method, or using the godot.NavigationPolygon.addPolygon
method.
Using godot.NavigationPolygon.addOutline
:
var polygon = NavigationPolygon.new()
var outline = PoolVector2Array([Vector2(0, 0), Vector2(0, 50), Vector2(50, 50), Vector2(50, 0)])
polygon.add_outline(outline)
polygon.make_polygons_from_outlines()
$NavigationPolygonInstance.navpoly = polygon
Using godot.NavigationPolygon.addPolygon
and indices of the vertices array.
var polygon = NavigationPolygon.new()
var vertices = PoolVector2Array([Vector2(0, 0), Vector2(0, 50), Vector2(50, 50), Vector2(50, 0)])
polygon.set_vertices(vertices)
var indices = PoolIntArray([0, 1, 2, 3])
polygon.add_polygon(indices)
$NavigationPolygonInstance.navpoly = polygon
Constructor
Variables
Methods
addOutline(outline:HaxeArray<Vector2>):Void
Appends a godot.Vector2
that contains the vertices of an outline to the internal array that contains all the outlines. You have to call godot.NavigationPolygon.makePolygonsFromOutlines
in order for this array to be converted to polygons that the engine will use.
addOutlineAtIndex(outline:HaxeArray<Vector2>, index:Int):Void
Adds a godot.Vector2
that contains the vertices of an outline to the internal array that contains all the outlines at a fixed position. You have to call godot.NavigationPolygon.makePolygonsFromOutlines
in order for this array to be converted to polygons that the engine will use.
addPolygon(polygon:HaxeArray<Int>):Void
Adds a polygon using the indices of the vertices you get when calling godot.NavigationPolygon.getVertices
.
clearOutlines():Void
Clears the array of the outlines, but it doesn't clear the vertices and the polygons that were created by them.
clearPolygons():Void
Clears the array of polygons, but it doesn't clear the array of outlines and vertices.
inlinegetOutline(idx:Int):Array<Vector2>
Returns a godot.Vector2
containing the vertices of an outline that was created in the editor or by script.
inlinegetPolygon(idx:Int):Array<Int>
Returns a Int
containing the indices of the vertices of a created polygon.
inlinegetVertices():Array<Vector2>
Returns a godot.Vector2
containing all the vertices being used to create the polygons.
removeOutline(idx:Int):Void
Removes an outline created in the editor or by script. You have to call godot.NavigationPolygon.makePolygonsFromOutlines
for the polygons to update.
setOutline(idx:Int, outline:HaxeArray<Vector2>):Void
Changes an outline created in the editor or by script. You have to call godot.NavigationPolygon.makePolygonsFromOutlines
for the polygons to update.
setVertices(vertices:HaxeArray<Vector2>):Void
Sets the vertices that can be then indexed to create polygons with the godot.NavigationPolygon.addPolygon
method.