I've recently discovered that a body can have more than one fixture and therefore more than one shape. This would come in very handy for the current game i'm working on. So I decided to run some tests.
As far as I can see rectangle seems to work fine. I can add as many rectangle shapes and their fixtures within the same parent body/fixture and they all move together as one and respond to forces as one. However I can't get a circle shape to behave the same way.
Some sample code, you can use the up and down keys to move the body, but something weirds going on with the circle shape
version 0.10
Code: Select all
function love.load()
world = love.physics.newWorld(0, 0, true)
main_body = love.physics.newBody(world, 400, 300, "dynamic")
main_shape = love.physics.newRectangleShape(64,64)
main_fixture = love.physics.newFixture(main_body, main_shape)
rect_shape = love.physics.newRectangleShape(-10,-10,4,4)
rect_fixture = love.physics.newFixture(main_body, rect_shape)
circle_shape = love.physics.newCircleShape(main_body:getX(), main_body:getY(), 4)
circle_fixture = love.physics.newFixture(main_body, circle_shape)
end
function love.update(dt)
world:update(dt)
if love.keyboard.isDown("down") then
main_body:applyForce(0,200)
elseif love.keyboard.isDown("up") then
main_body:applyForce(0,-200)
end
end
function love.draw()
love.graphics.polygon("line", main_body:getWorldPoints(main_shape:getPoints()))
love.graphics.polygon("line", main_body:getWorldPoints(rect_shape:getPoints()))
local shape_x, shape_y = circle_shape:getPoint()
love.graphics.circle("line", shape_x, shape_y, circle_shape:getRadius(), 100)
end
Best regards,
Thanks!