Page 1 of 1
love.graphics.polygon Help
Posted: Thu Jul 01, 2010 2:52 am
by Someguynamedpie
Whats the syntax for it? I thought it was {{X=0,Y=2},etc}
Re: love.graphics.polygon Help
Posted: Thu Jul 01, 2010 3:26 am
by TechnoCat
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.
Re: love.graphics.polygon Help
Posted: Thu Jul 01, 2010 2:25 pm
by Snow
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.
Re: love.graphics.polygon Help
Posted: Thu Jul 01, 2010 4:19 pm
by Robin
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.
Re: love.graphics.polygon Help
Posted: Thu Jul 01, 2010 4:50 pm
by Snow
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, ...}.
Re: love.graphics.polygon Help
Posted: Fri Jul 02, 2010 1:43 am
by Someguynamedpie
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}?
Re: love.graphics.polygon Help
Posted: Fri Jul 02, 2010 2:52 am
by Snow
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.
[Response]Eh?
Posted: Mon Jul 05, 2010 12:06 pm
by rhezalouis
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:
Re: [Response]Eh?
Posted: Mon Jul 05, 2010 1:00 pm
by thelinx
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.
Re: love.graphics.polygon Help
Posted: Mon Jul 05, 2010 5:29 pm
by pekka
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