Question about physic objects

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
NC22
Prole
Posts: 9
Joined: Sat Jul 16, 2011 12:36 am

Question about physic objects

Post by NC22 » Sat Jul 16, 2011 1:35 am

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
Attachments
tr.jpg
tr.jpg (14.16 KiB) Viewed 1002 times
Last edited by NC22 on Sat Jul 16, 2011 4:42 am, edited 1 time in total.

User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Question about physic objects

Post by Robin » Sat Jul 16, 2011 2:27 am

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)
Help us help you: attach a .love.

NC22
Prole
Posts: 9
Joined: Sat Jul 16, 2011 12:36 am

Re: Question about physic objects

Post by NC22 » Sat Jul 16, 2011 4:43 am

Yes. That was a problem. Thanks for help!

User avatar
Solemnly07
Prole
Posts: 4
Joined: Thu Aug 04, 2011 12:22 pm

Re: Question about physic objects

Post by Solemnly07 » Thu Aug 04, 2011 12:41 pm

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.
"I need not to be Right, I just don't have to be Wrong"

User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Question about physic objects

Post by Robin » Thu Aug 04, 2011 2:14 pm

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.
Help us help you: attach a .love.

User avatar
Solemnly07
Prole
Posts: 4
Joined: Thu Aug 04, 2011 12:22 pm

Re: Question about physic objects

Post by Solemnly07 » Thu Aug 04, 2011 4:02 pm

Thanks really helped! :D
"I need not to be Right, I just don't have to be Wrong"

Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests