Creating and drawing polygons

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Sheepiedog
Prole
Posts: 4
Joined: Sun Feb 23, 2020 4:50 pm

Creating and drawing polygons

Post 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!
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: Creating and drawing polygons

Post 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.
Sheepiedog
Prole
Posts: 4
Joined: Sun Feb 23, 2020 4:50 pm

Re: Creating and drawing polygons

Post 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?
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: Creating and drawing polygons

Post 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.
dezoitodemaio
Prole
Posts: 15
Joined: Mon Oct 26, 2020 2:02 pm

Re: Creating and drawing polygons

Post 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.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Semrush [Bot] and 6 guests