Multiple fixtures per body (love.physics)
Posted: Fri Sep 18, 2015 6:36 pm
Hello everybody,
i have a problem with love.physics. I have created a little test-game. In this game i create one body and attach multiple fixtures (+shapes). At the update-method i rotate the body. All works fine, but the graphical result is not what i expected. Here is the code and a graphic explain what i expect and what i get.
What i'm doing wrong?
https://love2d.org/imgmirrur/zmzGppo.png
Thanks for your help.
Christian
i have a problem with love.physics. I have created a little test-game. In this game i create one body and attach multiple fixtures (+shapes). At the update-method i rotate the body. All works fine, but the graphical result is not what i expected. Here is the code and a graphic explain what i expect and what i get.
What i'm doing wrong?
https://love2d.org/imgmirrur/zmzGppo.png
Code: Select all
Test = Class('Test');
function Test:initialize()
local size = 25;
local x, y = 0, 0;
self.body = love.physics.newBody(World, 350, 250, "dynamic");
for i=0, 2, 1 do
local shape = love.physics.newRectangleShape(x, y, size, size, 0);
local fixture = love.physics.newFixture(self.body, shape, 1);
x = x + size;
end
end
function Test:draw()
local fixtures = self.body:getFixtureList();
for idx, fixture in pairs(fixtures) do
local shape = fixture:getShape();
local x, y = self.body:getWorldPoints(shape:getPoints());
love.graphics.setColor(255, 0, 0, 255);
love.graphics.rectangle("line", x, x, 25, 25);
love.graphics.setColor(255, 0, 0, 50);
love.graphics.rectangle("fill", y, y, 25, 25);
end
end
function Test:update(dt)
self.body:applyTorque(100);
end
Christian