So I'm making a top down game with a background that scrolls when the player is moving but usuallly the player goes to fast and he goes off screen. How do I stop this? This is my code:
Code: Select all
function love.load()
love.graphics.set3D(true)
love.graphics.setScreen('top')
background = love.graphics.newImage('background.png')
youngBoy = love.graphics.newImage('youngboy.png')
youngboyx = 0
youngboyy = 0
backgroundx = 0
backgroundy = 0
distanceBetween = backgroundy - youngboyy
end
function love.draw()
love.graphics.draw(background, backgroundx, backgroundy)
love.graphics.draw(youngBoy, youngboyx, youngboyy)
end
function love.update(dt)
if love.keyboard.isDown("right") then
youngboyx = youngboyx + 2
end
if love.keyboard.isDown("left") then
youngboyx = youngboyx - 2
end
if love.keyboard.isDown("up") then
youngboyy = youngboyy - 2
end
if love.keyboard.isDown("down") then
youngboyy = youngboyy + 2
end
if love.keyboard.isDown("down") then
backgroundy = backgroundy - 5
end
if love.keyboard.isDown("up") then
backgroundy = backgroundy + 5
end
function love.keypressed(key)
if key == 'start' then
love.event.quit()
end
end