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 »

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: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: I don't understand love.load

Post by BlackBulletIV »

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 »

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: 1261
Joined: Wed Dec 29, 2010 8:19 pm
Location: Queensland, Australia
Contact:

Re: I don't understand love.load

Post by BlackBulletIV »

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 »

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 »

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

Who is online

Users browsing this forum: No registered users and 2 guests