SceneManager for p5.js games and applications
Switch branches/tags
Nothing to show
Clone or download
Veteanu Code refactor
Latest commit c22b2e3 Jun 19, 2018
Failed to load latest commit information.
gamejs Code refactor Jun 19, 2018
img Initial version Feb 25, 2017
lib Code refactor Jun 19, 2018 . Jun 16, 2018
game.html Initial version Feb 25, 2017
sample.html Code refactor Jun 19, 2018
sample_instance.html Initial version Feb 25, 2017

p5.js SceneManager

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

You can try online the SceneManager using the following demos:

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.