Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The <code>love.load</code> function runs only once. As you mention, it's generally used to set up data structures and pre-load other resources. You can use it to handle both the world pre-load and the menu pre-load. Then, control what is active via some sort of state. A simplified example:</p> <pre><code>local state = "menu" function love.load() preLoadMenu() preLoadWorld() end function love.update(dt) if state == "menu" then updateMenu() else updateWorld() end end function love.draw() if state == "menu" then drawMenu() else drawWorld() end end function love.mousepressed(x, y, button) if startClicked(x,y,button) then state = "world" end end </code></pre> <p>It's conceivable that you won't want to pre-load absolutely everything for your game on load. Maybe your game is just too big. If that's the case, consider working with an active scene. A scene might be the menu or maybe it's a game level. Again, a simplified example:</p> <pre><code>local currentScene function love.load() currentScene = loadMenu() end function love.update(dt) currentScene.update(dt) end function love.draw() currentScene.draw() end function love.mousepressed(x, y, button) if startClicked(x,y,button) then currentScene = loadWorld() end end </code></pre> <p>This second option is much more flexible in the long run. It can handle any number and type of scenes without conditional logic for each. It will require a little "object" thinking. All scenes need a consistent way to update and draw. </p> <p>If your world takes a while to load, you may want to display a temporary "world is loading" scene so your users don't get impatient.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload