Hello,
I'd like to create some variable Polygons with the love.physics engine. Since 0.8 I do this with "shape = love.physics.newPolygonShape( x1, y1, x2, y2, x3, y3, ... )". Indeed, my points are in a table. How can I convert my table (of variable size) to anything, that would fit into the new constructor?
Thanks for any help,
kpj
Create Polygon
Re: Create Polygon
Lua's unpack() should do the trick.
Code: Select all
local t = {x1, y1, x2, y2, x3, y3, ...}
shape = love.graphics.newPolygonShape(unpack(t))
ALL CREATURE WILL DIE AND ALL THE THINGS WILL BE BROKEN. THAT'S THE LAW OF SAMURAI.
Re: Create Polygon
Yes, that did it
Now there is another problem, I can only create a polygon with up to 8 different points.
In my programm, I want the user to draw a shape, and then add this shape to love.physics, so it could interact with all other objects.
Any suggestions how I could do this? Maybe I do not need a polygon?
Now there is another problem, I can only create a polygon with up to 8 different points.
In my programm, I want the user to draw a shape, and then add this shape to love.physics, so it could interact with all other objects.
Any suggestions how I could do this? Maybe I do not need a polygon?
Re: Create Polygon
Polygons can only be up to 8 sides but you could try attahing multiple shapes together and treat them as one
Your screen is very zoomed in...
Re: Create Polygon
Nice idea, I tried it:
Note: "drawmevert" contains all coordinates in the following pattern: "x1, y1, x2, y2, ..."
Sorry for stupid code, I started learning lua yesterday
Of course this line
needs to be changed, but I did not completely understand ithe meaning of "0,0" (is it the middle, upper-left corner, etc?!).
Furthermore this code gives me the following error:
What extactly does it mean? I tried google, but it did not reveal anything helpful
Any suggestions ?
Note: "drawmevert" contains all coordinates in the following pattern: "x1, y1, x2, y2, ..."
Code: Select all
function create_poly()
local tsize = table.getn(drawmevert)
local verter = {}
local vt = {}
for i,v in ipairs(drawmevert) do
-- divide all entries in 8 sized chunks
table.insert(vt, v)
if i % 8 == 0 then
table.insert(verter, vt)
vt = {}
end
end
if table.getn(vt) ~= 0 then
table.insert(verter, vt)
end
--[[print(tsize .. " nums -> " .. tsize/2 .. " coords")
print("into " .. table.getn(verter) .. " tables")
for i,v in ipairs(verter) do
print(i .. " | num-items: " .. table.getn(v))
end]]
local newp = {}
for i,v in ipairs(verter) do
newp = {body = love.physics.newBody(world, 0, 0), shape = love.physics.newPolygonShape(unpack(v))}
local fixture = love.physics.newFixture(newp.body, newp.shape)
table.insert(newp, fixture)
table.insert(object.polygs, newp)
end
end
Of course this line
Code: Select all
love.physics.newBody(world, 0, 0)
Furthermore this code gives me the following error:
Code: Select all
Box2D error: edge.LengthSquared() > b2_epsilon * b2_epsilon
Any suggestions ?
Re: Create Polygon
You can try use physics.newChainShape. here is an exampel: use l to draw a line and i to make its solid. u, n and p for poly
- Attachments
-
- phys11.love
- (103.03 KiB) Downloaded 173 times
Re: Create Polygon
Thanks a lot!
That was perfect
That was perfect
Who is online
Users browsing this forum: aikusuuta, Bing [Bot], Google [Bot] and 7 guests