love.graphics.polygon Help
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- 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: Milwaukee, WI
- 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.
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
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
Not if they use the format {{x, y}, {x, y}, ...}, though.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.
Help us help you: attach a .love.
Re: love.graphics.polygon Help
Just tested it, TechnoCat had it right and unpacking works.Robin wrote:Not if they use the format {{x, y}, {x, y}, ...}, though.
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}?
{{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
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
- 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
you don't need to unpack the list of coordinates. :glee:
Code: Select all
love.graphics.polygon("line", 10, 10, 20, 20, 10, 20);--and
love.graphics.polygon("line", {10, 10, 20, 20, 10, 20});
Aargh, I am wasting my posts! My citizenshiiiip...
Re: [Response]Eh?
According to the wiki, this is the case.rhezalouis wrote:IIRC, the love.graphics.polygon handles both theyou don't need to unpack the list of coordinates. :glee:Code: Select all
love.graphics.polygon("line", 10, 10, 20, 20, 10, 20);--and love.graphics.polygon("line", {10, 10, 20, 20, 10, 20});
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
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: Amazon [Bot], Bing [Bot], Google [Bot] and 7 guests