GithubHelp home page GithubHelp logo

love-scene's Introduction

love-scene

A very basic LÖVE scene manager.

How to Use

Add included main.lua to your project folder. Then, require "scene" on every file you want to load a scene. By default, the first scene loaded is scenes/main.lua.

Configuration

Customize first scene to load by editing FIRST_SCENE variable on main.lua. By default, scenes are loaded from scenes folder of main folder. You can change it by editing scenesFolder variable.

Defining a Scene

A scene file is a .lua file that returns a table with functions with the same name as LÖVE callbacks, plus unload (if needed). load will be called on next scene when it's loaded, and unload will be called when the current scene is about to be unloaded.

Example

require "scene" -- only needed to load another scene

local s = {} -- define the table that will be returned

function s.load() -- first function to be called by scene manager
    print "Scene loaded"
end

function s.unload() -- last function to be called by scene manager before unload
    print "Scene unloaded"
end

function s.draw() -- a LOVE callback
    love.graphics.print("Drawing scene",0,0)
end

function s.keypressed(key) -- another LOVE callback
    if key == "escape" then
        Scene.Load("anotherScene") -- will try to load "anotherScene.lua" on "scenes" folder
    end
end

return s -- this is important!

Documentation

Every scene must return a table that contains LÖVE callbacks. Every callback is optional, just like main.lua.

Scene.Load(name)

Unloads current scene (if any) by calling unload callback on current scene, loads the new scene (the <name>.lua file on "scenes" folder) and call load callback on the new scene. If <name>.lua doesn't exist, an error is raised.

Parameters

  • name: the scene file name, without .lua part (Example: if you want to load main.lua on scenes folder, you need to call Scene.Load("main")).

Callbacks

Scene manager supports any callback that LÖVE supports, thanks to modified love.run inside included main.lua. Also, it supports unload callback, used to unload any resources that won't be used anymore on the current scene and the GC can't handle (like physics callbacks and anything like that).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.