Page 1 of 1

When to use love.load()?

Posted: Wed Mar 27, 2013 2:40 am
by vine
I don't understand the purpose of love.load().
It loads all data within the function before the window is created, but what's the point in using it, as opposed to simply putting data outside the function?

ie:

Code: Select all

rat = love.graphics.newImage("rat.png")
VS

Code: Select all

function love.load()
    rat = love.graphics.newImage("rat.png")
end
What benefit does this have, and when is it appropriate to use?

Re: When to use love.load()?

Posted: Wed Mar 27, 2013 3:26 am
by Boolsheet
love.load is mainly a design thing that lets you separate the loading part of the game into its own function. There is one difference, however. The random seed gets initialized just before love.load gets called. If some code uses math.random before that, it will always get the same sequence.

Also, main.lua and love.load should get executed after the window has been created. Unless you disabled it in conf.lua and create the window yourself.