Drawing dynamic custom shapes from edge coordinates


Hi folks,

I’ve done a lot of searching for a solution but with no luck I’ve made an account here. Hopefully someone can help.

I’m working on porting a very simple game I wrote in python using pygame over to Defold. One thing I used in that project a lot (where I had to render everything manually), was generation and drawing of completely arbitrary shapes. i.e. - I provide a list of 2D coordinates, and a line is drawn from one to the other in order. Optionally, the shape can be filled with some chosen color (in my use case I would like it filled).

So for example I could programmatically generate three coordinates of a triangle based on some game logic:

[ (0,0), (0.5, 1), (1, 0) ]

pass this in to some function and it would render the triangle.

Any suggestions on how to do this in Defold? Or (and I hope this isn’t the solution as I’m really enjoying the engine), suggestions of an engine more suited to what I need to do? This kind of thing is very useful for quick prototyping.

Thanks :slight_smile:



Defold has draw line (meant for debugging).

msg.post("@render:", "draw_line", { start_point = vmath.vector3(0, 0, 0), end_point = vmath.vector3(1000, 1000, 0), color = vmath.vector4(1, 1, 1, 1) } )

There is now Draw Pixels (Native Extension) too.