How do you make a polygon of an indeterminate/redimensionable number of points?

I'd like to make a polygon and keep adding points to it, cause I don't know how many it will have

ie:
local points = pd.geometry.polygon.new()
points.addpoint(x,y)

Keep track of your points in another table and every time there's a change delete and recreate the polygon using one of the below methods:

playdate.geometry.polygon.new(x1, y1, x2, y2, ..., xn, yn) 
playdate.geometry.polygon.new(p1, p2, ..., pn)
playdate.geometry.polygon.new(numberOfVertices)

It's not ideal. But the process should be invisible to the user and for you some garbage collection churn.

It would be nice to have the ability to insert a point at an arbitrary place in the series of points of a polygon.

Dang.

This means I have to use playdate.geometry.polygon.new(numberOfVertices) and set each index manually before drawing, which means 2 lists are kept instead of 1, which will affect performance...

I think I'll just have to skip using polygon and draw lines instead then.

That's all polygon does anyway?

Don't be sure of the affects on performance until you've tried it. Please report your benchmarks.

1 Like