function love.load()
triangle={a = { x = 20, y = 20},
b = { x = 40, y = 20},
c = { x = 30, y = 40}
}
end
function love.draw()
love.graphics.polygon('fill',triangle)
end
Is that possible?
Last edited by jurses on Fri Oct 30, 2015 1:27 pm, edited 2 times in total.
local tri = {
a = { x = 20, y = 20},
b = { x = 40, y = 20},
c = { x = 30, y = 40},
}
function createTriangle(t)
return {t.a.x, t.a.y, t.b.x, t.b.y, t.c.x, t.c.y}
end
function love.draw()
love.graphics.polygon('fill',createTriangle(tri))
end
*Citation needed
Okay, okay, this is a very specific code snippet, so it has a dozen catches, and you really shouldn't do this, but meh.
Also, no such thing as a function/callback called love.graphics(), you probably meant love.draw()
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
local tri = {
a = { x = 20, y = 20},
b = { x = 40, y = 20},
c = { x = 30, y = 40},
}
function createTriangle(t)
return {t.a.x, t.a.y, t.b.x, t.b.y, t.c.x, t.c.y}
end
function love.draw()
love.graphics.polygon('fill',createTriangle(tri))
end
*Citation needed
Okay, okay, this is a very specific code snippet, so it has a dozen catches, and you really shouldn't do this, but meh.
Also, no such thing as a function/callback called love.graphics(), you probably meant love.draw()
Thanks that works, but I do not understand why I shouldn't do this.
It's usually faster to not have an extra function sorely for putting some data into another representation where you could just use the form love.graphics.polygon asks for (the simple numerically indexed table that asks for vertex points, as in, coordinate pairs of your polygon).
That representation is generic, in that, if you want a septagon (7-sided polygon) instead of a triangle, you don't need to do anything, but have 8 more values in your table, the index can increase simply, and you have no problems.)
Using your labelled tables (the triangle table having a,b,c string keys, and x and y keys inside those tables) is hard because the code doesn't know what comes after 'c'; not to mention that you need to edit your converter function to deal with it.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
zorg wrote:It's usually faster to not have an extra function sorely for putting some data into another representation where you could just use the form love.graphics.polygon asks for (the simple numerically indexed table that asks for vertex points, as in, coordinate pairs of your polygon).
That representation is generic, in that, if you want a septagon (7-sided polygon) instead of a triangle, you don't need to do anything, but have 8 more values in your table, the index can increase simply, and you have no problems.)
Using your labelled tables (the triangle table having a,b,c string keys, and x and y keys inside those tables) is hard because the code doesn't know what comes after 'c'; not to mention that you need to edit your converter function to deal with it.
Ok, thanks for the tip . Then I will use the direct value for the polygon.