I want to be able to make a lua module for each of my levels and have a controller that draws/updates/loads... the current level. Everything is working in the controller but my level is only being drawn once (I put a print in the draw method and it's only called once). Here is my level "class" and my main menu "level". I think my problem is something with how I am passing my functions into the level module.
level.lua
Code: Select all
Level = {}
Level.__index = Level
function Level:new(config)
local l = {}
setmetatable(l,Level)
l.name = config.name
l.load = config.load
l.draw = config.draw
l.update = config.update
return l
end
function Level:load()
-- Defined in :new
end
function Level:draw()
-- Defined in :new
end
function Level:update(dt)
-- Defined in :new
end
return Level
Code: Select all
Level = require('level')
MainMenu = {}
MainMenu.__index = MainMenu
function MainMenu:load()
love.window.setTitle("Main Menu")
end
function MainMenu:update(dt)
end
function MainMenu:draw()
print("Drawing") -- THIS only happens once
love.graphics.print("Level One", 100, 100)
end
---------------- I think, below is the issue -----------
MainMenu = Level:new({
name = "Main Menu",
load = MainMenu:load(),
draw = MainMenu:draw(),
update = MainMenu:update()
})
return MainMenu
This may seem more complicated than needed but I have some ideas on where I want to go with this. ALSO, I'm just learning lua so there may be some obvious or stupid things in this code