Page 1 of 1

Question about physic objects

Posted: Sat Jul 16, 2011 1:35 am
by NC22
I try to make my own physic object with some image, but image dont match with physic model.
size of image 56x56 . here is a code for example

Code: Select all

function love.load()
    love.graphics.setLineWidth(2)
    world = love.physics.newWorld(-650, -650, 650, 650) 
    world:setGravity(0, 150)
    boximage = love.graphics.newImage("love_cube.png")
    boxbody = love.physics.newBody(world, 150, 0, 150 , 45)
    boxshape = love.physics.newRectangleShape(boxbody , 150, 0, 56, 56,9)
end
function love.update(dt)
    world:update(dt)
end
function love.draw()
    love.graphics.polygon("line", v.s:getPoints())
    love.graphics.draw(v.i, boxbody :getX(),  boxbody :getY(), boxbody :getAngle(), 1, 1, 28, 28)
end
Thats screenshot shows how look that in game

Re: Question about physic objects

Posted: Sat Jul 16, 2011 2:27 am
by Robin
The shape is offset, so that makes sense. Try replacing the last line in love.load with

Code: Select all

boxshape = love.physics.newRectangleShape(boxbody, 0, 0, 56, 56)

Re: Question about physic objects

Posted: Sat Jul 16, 2011 4:43 am
by NC22
Yes. That was a problem. Thanks for help!

Re: Question about physic objects

Posted: Thu Aug 04, 2011 12:41 pm
by Solemnly07
Hi, I'm new here and I know forum rules. (No double posting of same topics).
I think it's quite the same topic but, I also need help.

Does your block move or is it static? Because I want to make an object and place an Image on it.
I want to make the object move along with the image, is it possible?
Because I've been trying to make an "Image" become a Physics "object".
Do you get what I mean? :D

Sorry, I'm still a fresh apple.

Re: Question about physic objects

Posted: Thu Aug 04, 2011 2:14 pm
by Robin
How you do that in LÖVE is you take an image and you take a body, and you draw that image at the location of the body:

Code: Select all

love.graphics.draw(myimage, mybody:getX(), mybody:getY())
There's more to it, but that's the basic thing to know.

Re: Question about physic objects

Posted: Thu Aug 04, 2011 4:02 pm
by Solemnly07
Thanks really helped! :D