2
\$\begingroup\$

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?

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

EDIT

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")
  scene_manager.change("foo")
end

The change method looks like this:

  unload_scene()
  current_scene = scenes[scene_name]
  load_scene()

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.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .