Is it possible to have love.load(), love.draw() and love.update() in different files? and if so how would I go about doing that?



It seems I misunderstood your question; you are not asking how to switch between different callbacks, you want to have them in different files.

The principle is the same:

load_module = require "main_load"
love.load = load_module.load

I've written a scene manager to do just that. I will open source it some day but to give you an idea here's how it is used:

-- main.lua
function love.load()
  scene_manager.add(require "scenes/foo")
  scene_manager.add(require "scenes/bar")

The change method looks like this:

  current_scene = scenes[scene_name]

Basically you need to iterate over the various methods (load, update as well as mousereleased for instance) and then do love[method_name] = nil.

Then in load_scene you need to set it love[method_name] = current_scene[method_name].

I know this is not a comprehensive answer but it should get you started. So, yes, it can be done.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.