Page 1 of 1

Bind picture to body, apply force to body

Posted: Mon Jun 18, 2012 5:55 pm
by tietze111
Hi,
I wanted to create a body and bind a picture to it. Then I wanted to apply a force to the body (something like gravity) to get the body moving. The picture should move with the body. My attempt for this was:

Code: Select all

function love.load()
world = love.physics.newWorld( 0, 0, 1000, 800, xg, yg, sleep )
body = love.physics.newBody( world, 100, 100, dynamic)
background = love.graphics.newImage("background.jpg")
picture = love.graphics.newImage("picture.png")

body:applyForce(0,20)
bxp = 100
byp = 100
end

function love.draw()
bxp = body:getX()
byp = body:getY()

love.graphics.draw(background)
love.graphics.draw(picture, bxp, byp)
end
Thank you in advance,
tietze111

Re: Bind picture to body, apply force to body

Posted: Mon Jun 18, 2012 7:36 pm
by juno
Hey.
There's a couple of small things preventing this from working.
You can create your world like this in 0.8.0..

Code: Select all

world = love.physics.newWorld( 0, 400, true )
When you are creating your body, you need to put the dynamic in " "... ie. pass it as a string

Code: Select all

body = love.physics.newBody( world, 100, 100, "dynamic")
You will also need an update function...

Code: Select all

function love.update(dt)
	world:update(dt)
end
That should get you started with making the object and image move