I can't apply gravity on my character.
Posted: Sat Nov 07, 2015 6:08 pm
I've write this code:
I can move right and left my character but he doesn't fall down. Why?
(Scuse me if i've done some grammar error, i can't speak english very well)
Code: Select all
function love.load(arg)
player = { x = 200, y = 210, speed = 150, img = nil }
player.img=love.graphics.newImage ("char.png")
love.physics.setMeter (32)
world = love.physics.newWorld(0 , 32*9.81)
player.body = love.physics.newBody (world, player.x, player.y, dynamic)
player.shape = love.physics.newRectangleShape(32, 64)
player.fixture = love.physics.newFixture (player.body, player.shape, 5)
end
function love.update(dt)
if love.keyboard.isDown ("a") then
player.x=player.x-player.speed*dt
end
if love.keyboard.isDown ("d") then
player.x=player.x+player.speed*dt
end
end
function love.draw(dt)
love.graphics.draw(player.img, player.x, player.y)
end
(Scuse me if i've done some grammar error, i can't speak english very well)