Code Monkey home page Code Monkey logo

p5.scenemanager's Introduction

p5.js SceneManager

p5.js SceneManager is used by countless of p5.js developers across the world to add scene management capabilities to their p5.js sketches. If you are using 'p5.js SceneManager' in your project, it will be great if you share the details of your project with me (I may even feature your project on this page).

News

  • codeguppy.com coding platform is now using a modified version of 'p5.js SceneManager'. Check it out - is super cool!

JavaScript projects

Description

p5.js SceneManager helps you create p5.js sketches with multiple states / scenes. Each scene is a like a sketch within the main sketch. You focus on creating the scene like a regular sketch and SceneManager ensure scene switching routing the main setup(), draw(), mousePressed(), etc. events to the appropriate current scene.

Instead of putting all your code in the main setup() and draw() like this:

function setup() {

}

function draw() {

}

... you put each scene code in the setup() and draw() methods of individual Scene classes:

// Intro scene constructor function
function Intro()
{
    this.setup = function() {
    }

    this.draw = function() {
    }

    this.keyPressed = function() {
        // switch the scene
        this.sceneManager.showScene( Game );
    }
}

// Main games scene constructor function
function Game()
{
    this.setup = function() {
    }

    this.draw = function() {
    }
}

The SceneManager will provide you with methods necesary to switch to the appropriate scene and route the main p5.js events to your defined events.

Source Code

Source code is located in lib/scenemanager.js

Demo Code

For demo please check sample.html, sample_instance.html and game.html

Online demo

If you want to play with scenes in an online playground, just go to codeguppy.com/code.html code editor.

If you want to try the classical standalone demostrations of SceneManager, then check-out the following examples:

Code Online version
sample.html sample.html
sample_instance.html sample_instance.html
game.html game.html

Future development

The library can be further extended with features such as:

  • routing of more / all events to the appropriate scene class
  • running of multiple scenes in parallel (overlapped)
  • running of multiple scenes in parallel in individual areas of a bigger canvas

If you are interested in these features, please open an issue here on GitHub.

License

CC BY 2.0

VMA

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.