edited December 2017 in 2D

OpenGLES continuously reports that the rectangular polygon drawn by the following script snippet is invalid, or a 'bad polygon', i however can not see as to why it so is, i believe i'm doing everything according to the docs.

The code draws four circles where the corners of the polygon are, but not the polygon, am i missing something here?

``````extends Node2D

var points
var point1
var point2
var point3
var point4

var colour = Color(175,175,175,1)

_set_vec()
set_process(true)

pass

func _set_vec():
points = Vector2Array()

var dim_x = get_viewport().get_rect().size.x / 2
var dim_y = get_viewport().get_rect().size.y / 2
var offset_x = get_viewport().get_rect().size.x / 3
var offset_y = get_viewport().get_rect().size.y / 3

# add 4 points to the array
point1 = Vector2(dim_x - offset_x, dim_y - offset_y)
point2 = Vector2(dim_x - offset_x, dim_y + offset_y)
point3 = Vector2(dim_x + offset_x, dim_y - offset_y)
point4 = Vector2(dim_x + offset_x, dim_y + offset_y)

points.append(point1)
points.append(point2)
points.append(point3)
points.append(point4)

pass

func _print_debug_dots():
print(point1)
print(point2)
print(point3)
print(point4)

func _process(delta):
update()

func _draw():
draw_circle(point1, 20, colour)
draw_circle(point2, 20, colour)
draw_circle(point3, 20, colour)
draw_circle(point4, 20, colour)

draw_colored_polygon(points, colour)
``````

• Maybe use PoolVector2Array instead of a Vector2Array?

It’s been awhile since I’ve worked with Godot to make polygons, but if what I remember holds you have to use a PoolVector2Array for any mesh/polygon. Things could have changed since I lasted used Godot though, so I’m not sure if that’s the case anymore...

• PoolVector2Array does not appear to be a valid constructor/available in the latest stable release, nor can be found at the stable's version docs. However, it appears to be similar in nature to Vector2Array.

I've successfully found an example that uses Vector2Array only, yet that example sometimes works while other times it echoes 'bad polygon' errors onto the console.

I wanted to find out how this thing worked with this snippet example. Should there be an order to how points are added to the array?