Page 1 of 1

Creating and drawing polygons

Posted: Thu Oct 29, 2020 10:00 pm
by Sheepiedog
I'm creating a pinball-like game, where a ball collides with convex polygons, as defined by a list of vertices and other parameters like bounciness, movement path, etc. You can see a screenshot of the game below.

Image

Everything works well, including collisions, but I have two problems I would like to resolve

1) Currently, I input the location and shape of every polygon as text in a .lua file. This is obviously very tedious. Is there some external program where I could visually draw some polygons, and export it as a list of vertices (and other parameters) that I can then import as a .lua?

2) I draw every polygon with love.graphics.polygon(), but I've heard meshes are more efficient. I can draw the polygons with meshes, but the problem is that I also use a budget glow effect by drawing several copies of each polygon below it with low transparency and varying linewidth. Can I mimic this with meshes, without creating several separate meshes for each polygon? Also, I always draw < 100 polygon per frame.. is it even worth it to use meshes?

Thanks!

Re: Creating and drawing polygons

Posted: Fri Oct 30, 2020 9:46 am
by grump
For static polygons that aren't too big, drawing them once to a Canvas would be a good solution.

Meshes are generally more efficient than immediate mode polygons, because they don't need to be rebuild every time. They are a little more complicated to build though. If you don't have a performance problem, or if you can use Canvases, you don't need to bother with meshes.

Re: Creating and drawing polygons

Posted: Fri Oct 30, 2020 10:59 am
by Sheepiedog
Thanks! Are you suggesting to draw each polygon to its own canvas? Or every polygon onto a single canvas? What if some of the polygons move relative to the others?

Re: Creating and drawing polygons

Posted: Fri Oct 30, 2020 11:17 am
by grump
It depends on how big and complex the polygons are, and the number of polygons and how many you need to draw per frame. If it's hundreds of large and unique polygons that need to be moved around independently, Canvas may use too much memory.
Meshes are never the wrong choice, but the "varying line width" thing could be difficult to pull off.
It's difficult to give good advice without knowing more details.

Re: Creating and drawing polygons

Posted: Sat Oct 31, 2020 4:04 pm
by dezoitodemaio
1) you can use https://www.mapeditor.org/, it has a geometry editor with rectangles, circles and polygons. You can also natively export the map to a .lua file.