• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

[SOLVED] Primitives, Concave Filled-in Polygon

Bentley

Member
I want to to create a concave polygon sprite from a surface. The player places points which connect (like the arc tool in the sprite editor). When the player re-clicks on a previous point, I use draw_primitive_begin/draw_vertex to make the shape.

draw_primitive_begin(pr_linestrip) will connect the lines and give me a concave shape, but it doesn't fill that shape like pr_trianglefan does. I want the shape filled so I can use its full bounding box.

Thanks for reading.
 

Nux

GameMaker Staff
GameMaker Dev.
The primitive types (pr_linestrip) wont really help much here on their own...

I made a script which uses the scan-line algorithm to draw a polygon from a list of points: https://gist.github.com/NuxiiGit/50a3aff1543c6ccf69456a5cfb86eb58. This feels like the only sensible way to draw arbitrary polygons.

An alternative way would be to triangulate the list of points using this function https://www.gmlscripts.com/script/polygon_to_triangles, which requires the points be defined counter-clockwise. Then you can draw each individual triangle yourself using the primitive functions and pr_trianglelist.

Both of these functions take ds_lists of the form [x1,y1, x2,y2, ...], so a ds_list of values where every first item is an x coordinate and every second item in a y coordinate.
 
Top