## love.graphics.polygon Help

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Someguynamedpie
Citizen
Posts: 71
Joined: Wed Mar 31, 2010 10:59 pm

### love.graphics.polygon Help

Whats the syntax for it? I thought it was {{X=0,Y=2},etc}

TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Denver, CO
Contact:

### Re: love.graphics.polygon Help

love.graphics.polygon()
love.graphics.polygon("line",0,0,10,0,0,10) would make a triangle from 0,0 10,0 to 0,10 I believe.

Snow
Prole
Posts: 16
Joined: Tue Jun 29, 2010 4:54 pm

### Re: love.graphics.polygon Help

If you already have a table of vertices you can use Lua's unpack(table) like love.graphics.polygon('line', unpack({x1, y1, x2, y2, x3, y3, ...})). I think it should work anyway.

Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

### Re: love.graphics.polygon Help

Snow wrote:If you already have a table of vertices you can use Lua's unpack(table) like love.graphics.polygon('line', unpack({x1, y1, x2, y2, x3, y3, ...})). I think it should work anyway.
Not if they use the format {{x, y}, {x, y}, ...}, though.

Snow
Prole
Posts: 16
Joined: Tue Jun 29, 2010 4:54 pm

### Re: love.graphics.polygon Help

Robin wrote:Not if they use the format {{x, y}, {x, y}, ...}, though.
Just tested it, TechnoCat had it right and unpacking works.
Edit: Right, on the wiki it accepts a table also so instead of using unpack you can just wrap the list in braces, like {x1, y1, x2, y2, ...}.

Someguynamedpie
Citizen
Posts: 71
Joined: Wed Mar 31, 2010 10:59 pm

### Re: love.graphics.polygon Help

Im having trouble: I have points formatted like this:
{{x=10,y=10},{x=30,y=30}}, how would i format it into 1 table like {10,10,30,30}?

Snow
Prole
Posts: 16
Joined: Tue Jun 29, 2010 4:54 pm

### Re: love.graphics.polygon Help

Someguynamedpie wrote:Im having trouble: I have points formatted like this:
{{x=10,y=10},{x=30,y=30}}, how would i format it into 1 table like {10,10,30,30}?

Code: Select all

points = {{x=10,y=10},{x=30,y=30}}
pointStack = {}

for k, v in pairs(points) do
table.insert(pointStack, v.x)
table.insert(pointStack, v.y)
end
This should do it.

rhezalouis
Party member
Posts: 100
Joined: Mon Dec 07, 2009 10:27 am
Location: Indonesia
Contact:

### [Response]Eh?

IIRC, the love.graphics.polygon handles both the

Code: Select all

love.graphics.polygon("line", 10, 10, 20, 20, 10, 20);--and
love.graphics.polygon("line", {10, 10, 20, 20, 10, 20});
you don't need to unpack the list of coordinates. :glee:
Aargh, I am wasting my posts! My citizenshiiiip...

thelinx
The Strongest
Posts: 848
Joined: Fri Sep 26, 2008 3:56 pm
Location: Sweden

### Re: [Response]Eh?

rhezalouis wrote:IIRC, the love.graphics.polygon handles both the

Code: Select all

love.graphics.polygon("line", 10, 10, 20, 20, 10, 20);--and
love.graphics.polygon("line", {10, 10, 20, 20, 10, 20});
you don't need to unpack the list of coordinates. :glee:
According to the wiki, this is the case.

pekka
Party member
Posts: 206
Joined: Thu Jan 07, 2010 6:48 am
Location: Oulu, Finland
Contact:

### Re: love.graphics.polygon Help

The second form was added to the docs quite recently, so it might not be widely known. I know this because I am the one responsible for adding it. I discovered the other usage from reading the C++ source and dutifully added it to the docs. I also had an example code snippet there, but then a site crash occurred ( ) and reverted the Wiki a couple of days backwards. I redid the explanation, but omitted the code example the second time, out of laziness probably.

It would probably be good to have a code snippet using both ways to draw a simple polygon there. I can add one soon, once I am on a LOVELY computer again. But anyone else can do it too

### Who is online

Users browsing this forum: raidho36, Sky_Render, steVeRoll and 18 guests