Coder Social home page Coder Social logo

opensourcegamedeveloper / screenmanager Goto Github PK

View Code? Open in Web Editor NEW

This project forked from rm-code/screenmanager

0.0 0.0 0.0 79 KB

Stackable Screen/State Management for the LÖVE framework.

Home Page: http://rm-code.github.io/screenmanager/

License: zlib License

Lua 100.00%

screenmanager's Introduction

ScreenManager

Version LOVE License

The ScreenManager library is a state manager at heart which allows some nifty things, like stacking multiple screens on top of each other.

It also offers hooks for most of LÖVE's callback functions. Based on the type of callback the calls are rerouted to either only the active screen (love.keypressed, love.quit, ...) or to all screens (love.resize, love.visible, ...).

Example

For a more complete example check out the example branch in this repository.

This is a simple example of how the ScreenManager should be used (note: You will have to change the paths in the example to fit your setup).

-- main.lua

local ScreenManager = require('lib.ScreenManager')

function love.load()
    local screens = {
        main = require('src.screens.MainScreen')
    }

    ScreenManager.init(screens, 'main')
end

function love.draw()
    ScreenManager.draw()
end

function love.update(dt)
    ScreenManager.update(dt)
end

Note how MainScreen inherits from Screen.lua. This isn't mandatory, but recommended since Screen.lua already has templates for most of the callback functions.

-- MainScreen.lua

local Screen = require('lib.Screen')

local MainScreen = {}

function MainScreen.new()
    local self = Screen.new()

    local x, y, w, h = 20, 20, 40, 20

    function self:draw()
        love.graphics.rectangle('fill', x, y, w, h)
    end

    function self:update(dt)
        w = w + 2
        h = h + 1
    end

    return self
end

return MainScreen

Documentation

An online documentation is available here.

screenmanager's People

Contributors

rm-code avatar pablomayobre avatar

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.