Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer 1

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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