npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

p5.scenemanager

v1.0.6

Published

Helps you create sketches with multiple states / scenes

Downloads

63

Readme

p5.js SceneManager

News

  • A modified version of 'p5.js SceneManager' is a key component of codeguppy.com - a new coding site for kids, teens and creative adults.

JavaScript projects

Note: If you are using p5.js SceneManager in your project, it will be great if you share the details of your project with me (totally optional though).

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.

Draw something in all scenes

if you wish, you can add a event to execute after each draw() of all scenes.

To do this, in your .js file that contains setup() to load the main scene (generally sketch.js), add a drawScene() global event, like this:

function setup() {
  ...

  let mgr = new SceneManager();
  mgr.wire();
  mgr.showScene(MainScene);
}

function drawScene() {
    // Draw something in the canvas,
    // after draw() of each scene
}

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.

License

CC BY 2.0

VMA