Physics: draw all shapes

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
xernobyl
Prole
Posts: 1
Joined: Tue Jun 12, 2012 3:43 am

Physics: draw all shapes

Post by xernobyl »

I began using LÖVE (and learning lua) yesterday just because.

I'm playing with physics fixing a few shapes to a body, and I can't find a way (variable / function) to get the position of a circle shape since CircleShape:getWorldCenter() was removed on 0.8.0. How am I supposed to get the position of each shape?

I'm now using body:getWorldPoint to convert the points I used to create the shapes, but that position is already somewhere without the need to recalculate it.
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: Physics: draw all shapes

Post by Boolsheet »

Yeah, CircleShape is currently missing a function that returns its position. There are plans for 0.8.1 to add CircleShape:getPoint. It's a bit inconvenient, but you have to store the position in a table and fall back to that for now.
The rest of the Shapes has :getPoints() functions that return the positions.
Shallow indentations.
User avatar
juno
Citizen
Posts: 85
Joined: Thu May 10, 2012 4:32 pm
Location: London

Re: Physics: draw all shapes

Post by juno »

i use a method in my base class to draw the polygons of each body in the world..here's what it looks like

Code: Select all

for _, v in ipairs(self.fixtures) do
			local tlx,tly,brx,bry = v:getBoundingBox( )
			love.graphics.push()
			love.graphics.setColor(0,255,255,50)
			love.graphics.rectangle("fill", tlx, tly, brx-tlx, bry-tly)
			love.graphics.pop()

		local shape = v:getShape()
		if shape:getType() == "polygon" then
			love.graphics.push()
			love.graphics.setColor(self.color)
				love.graphics.translate(self.body:getX(),  self.body:getY())
				love.graphics.rotate(self.body:getAngle())
			love.graphics.polygon("fill", shape:getPoints())
			love.graphics.pop()
		end

		if shape:getType() == "circle" then
			love.graphics.push()
			love.graphics.setColor(self.color)
			love.graphics.circle("fill", tlx+((brx-tlx)/2), tly+((bry-tly)/2) ,shape:getRadius(), 20)
			love.graphics.pop()
		end
		massDensityInfo = massDensityInfo.."\nFixture Density: "..v:getDensity()
	end
so for each type of shape - polygon or circle, it will draw the shape.
As Boolsheet pointed out, you need to store the circle position/radius in a separate table but it's not a difficult work around
wat ya mean she's in another castle!?
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Amazon [Bot], Bing [Bot], Google [Bot] and 9 guests