Hello. I do game. My character must move by "x" at left and right. When i don't use phisic model, i do it with change "x" of grafic in "update (dt)" function.
But now, when i use phisic model, i must do another method? Something with body? And what function it's must be? I wright my code heare.
Help me, please.
function load()
love.graphics.setBackgroundColor(212, 233, 247)
-- Create a world with size 2000 in every direction.
world = love.physics.newWorld(2000, 2000)
world:setGravity(0, 100)
-- Create the ground body at (0, 0) with mass 0.
ground = love.physics.newBody(world, 0, 0, 0)
-- Create the ground shape at (400,500) with size (600,10).
ground_shape = love.physics.newRectangleShape(ground, 0, 545, 2000, 10)
image = love.graphics.newImage("images/back.png")
colob1 = love.graphics.newImage("images/kolob.png")
-- Create a Body for the circle.
body = love.physics.newBody(world, 50, 512)
-- Attatch a shape to the body.
circle_shape = love.physics.newCircleShape(body, 28)
body:setMassFromShapes()
end
function draw()
love.graphics.draw(image, 515, 350)
love.graphics.draw(colob1,body:getX(), body:getY(), body:getAngle())
end
function update(dt)
world:update(dt)
end
function keypressed(k)
if k == love.key_up then
body:applyImpulse(0, -300000)
end
end
function load()
love.graphics.setBackgroundColor(212, 233, 247)
-- Create a world with size 2000 in every direction.
world = love.physics.newWorld(2000, 2000)
world:setGravity(0, 100)
-- Create the ground body at (0, 0) with mass 0.
ground = love.physics.newBody(world, 0, 0, 0)
-- Create the ground shape at (400,500) with size (600,10).
ground_shape = love.physics.newRectangleShape(ground, 0, 545, 2000, 10)
image = love.graphics.newImage("images/back.png")
colob1 = love.graphics.newImage("images/kolob.png")
x=50
y=512
-- Create a Body for the circle.
body = love.physics.newBody(world, x, y)
-- Attatch a shape to the body.
circle_shape = love.physics.newCircleShape(body, 28)
body:setMassFromShapes()
end
function draw()
love.graphics.draw(image, 515, 350)
love.graphics.draw(colob1,body:getX(), body:getY(), body:getAngle())
end
function update(dt)
world:update(dt)
if love.keyboard.isDown(love.key_left) then
x = x - 500 * dt
end
if love.keyboard.isDown(love.key_right) then
x = x + 500 * dt
end
body:setX( x )
end
function keypressed(k)
if k == love.key_up then
body:applyImpulse(0, -300000)
end
end
I'm not sure what you mean by "collision", I can't find any collision code in your code. I also tested it, and it seemed to work fine. Maybe you could say what the problem is in other words?