I don't understand love.load

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Trevor
Prole
Posts: 30
Joined: Thu Mar 31, 2011 4:14 pm

I don't understand love.load

Post by Trevor » Wed Apr 06, 2011 11:34 pm

load.load gets "called exactly once at the beginning of the game." How are the game assets loaded afterwards? I've been looking at the code from "Dave Gone Apeshit" and it doesn't call love.load after state changes.

Main

Code: Select all

...
state = menu
...
function love.load()
    ...
    if state.load then state.load() end
end
So menu.load is called here which loads menu assets I get that much.

Menu:

Code: Select all

if menuMode == "main" then
function menu.draw()
    ...
                if menu.button("NEW GAME", 475, 310) then
			game.load()
			state = game
		end
    ...
state is now game if you click "New Game" good so far. But now, since love.load only runs once how is game.load called since love.load will never be called again and state.load is in love.load?

User avatar
BlackBulletIV
Inner party member
Posts: 1260
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: I don't understand love.load

Post by BlackBulletIV » Wed Apr 06, 2011 11:46 pm

Wouldn't the loading for the load function for state be called in love.update or something when a state changes? If you need to load assets after the game starts up, you would most likely to so in the update stage, i.e. when love.update is called.

Anyway, this is just a game's use of love.load. love.load is called exactly once at the start of the game (you can call it again manually of course); that's all.

Trevor
Prole
Posts: 30
Joined: Thu Mar 31, 2011 4:14 pm

Re: I don't understand love.load

Post by Trevor » Thu Apr 07, 2011 12:04 am

Okay, I thought assets had be loaded in love.load. I didn't realize - despite looking right at the code :oops: - that assets can me loaded at any point. Thank you, sometimes it just takes an explanation. This helps a lot. Each time I call love.load the screen disappears for a moment which I really disliked.

User avatar
BlackBulletIV
Inner party member
Posts: 1260
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: I don't understand love.load

Post by BlackBulletIV » Thu Apr 07, 2011 12:48 am

No worries.

Calling love.load isn't a good thing, unless you want a complete reset (this relies on you doing all start up inside love.load) with some sort of delay. If you want to reset a game without delay, you should probably manually do it, by reseting player positions, removing enemies, or something like that.

User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: I don't understand love.load

Post by Robin » Thu Apr 07, 2011 5:36 am

love.load usually consists of two parts: loading resources and setting up state (player position, enemies, whatever). You can separate those, put the setting up part in another function and call that when you want to reset the game.
Help us help you: attach a .love.

Trevor
Prole
Posts: 30
Joined: Thu Mar 31, 2011 4:14 pm

Re: I don't understand love.load

Post by Trevor » Thu Apr 07, 2011 1:22 pm

Thanks, I'll definitely be doing that today. :)

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 6 guests