Page 1 of 1

Arguments for newPolygonShape()

Posted: Sun Aug 30, 2009 5:10 pm
by LagMasterSam
I'm experimenting with LÖVE for the first time and I'm a little puzzled about this function. I see in the documentation that...

love.physics.newPolygonShape( body, ... )

Synopsis
polygon = love.physics.newPolygonShape( body, ... )

Arguments
body The Body to attatch the polygon to.
... The vertices of the PolygonShape.

Returns
PolygonShape The new PolygonShape.

I assumed the vertices are pairs of numbers as shown in the Box2D manual so I did this...

Code: Select all

function load()
	-- Code Here
	TriImage1 = love.graphics.newImage("BlueTri01.png")
	world = love.physics.newWorld(2000,2000)	
	TriBody1 = love.physics.newBody(world,1000,1000)
	TriShape1 = love.physics.newPolygonShape(TriBody1, {-1,0}, {1,0}, {0,2})
end
However, I get this error message...
main.lua:6 Incorrect number of arguments. Got[4], expected at least [7]
Stack traceback:
[C]: in function 'newPolygonShape'
main.lua:6 in function <main.lua:1>
Does that mean my polygons must have 6 vertices, or am I missing something here?

Re: Arguments for newPolygonShape()

Posted: Sun Aug 30, 2009 5:18 pm
by bartbes
You don't have to group the arguments in tables,

Code: Select all

function load()
	-- Code Here
	TriImage1 = love.graphics.newImage("BlueTri01.png")
	world = love.physics.newWorld(2000,2000)	
	TriBody1 = love.physics.newBody(world,1000,1000)
	TriShape1 = love.physics.newPolygonShape(TriBody1, -1,0, 1,0, 0,2)
end
should work.

Re: Arguments for newPolygonShape()

Posted: Sun Aug 30, 2009 5:35 pm
by LagMasterSam
Thanks. I'm just used to a vertex being represented by a data structure.