Here is the code for reference:
Code: Select all
local Background = {}
function Background:load()
self.image = love.graphics.newImage("assets/background.jpg")
self.x = 0
end
function Background:update(dt)
if love.mouse.getX() > 420 then
self.x = self.x - 4 * dt
elseif love.mouse.getX() < 60 then
self.x = self.x + 4 * dt
end
end
function Background:draw()
love.graphics.draw(self.image, self.x, 0, 0, 4, 4)
end
return Background
Code: Select all
local Background = require("background")
function love.load()
Background.load()
end
function love.update()
Background.update(dt)
end
function love.draw()
Background.draw()
end