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
local Background = require("background")
function love.load()
Background.load()
end
function love.update()
Background.update(dt)
end
function love.draw()
Background.draw()
end
-- your original
function Background:load()
self.image = love.graphics.newImage("assets/background.jpg")
self.x = 0
end
-- this is syntactically the same code
function Background.load(self)
self.image = love.graphics.newImage("assets/background.jpg")
self.x = 0
end
-- either of these would work for calling the function
Background.load(Background)
Background:load()