Git Product home page Git Product logo

p5.scenemanager's Introduction

Hi there ๐Ÿ‘‹

My name is Marian Veteanu. Here you can find some of my old projects. Some of them go back to 1991.

If this seems fun, you can also visit some of my old websites:

โšก Note: Super-secret new projects are not here. โœ‰ Please get in touch with me to see what's new. You can reach me on:

Happy Coding!


Professional interests

  • scalable web architectures
  • microservice based architecture
  • no-code / low-code designs

Hobbies

The following are a few of my current recreational coding interests... may change in the future:

  • Coding education
  • Building CPUs from scratch (both hardware and emulated)
  • RISC-V and ARM ISAs
  • Emulators in general
  • Fantasy Consoles
  • Writing compilers and interpreters
  • Video consoles built using low-power microcontrollers
  • Bare-metal development for Raspberry Pi
  • Compiling in the browser
  • Web Technologies (vanilla, frameworks, APIs, etc.)
  • Web Assembly for web projects
  • Web Assembly on low-power microcontrollers
  • Retro computers
  • ZX-Spectrum (my first computer was HC-90 a clone of ZX-Spectrum 48K)
  • microcontrollers in general
  • Hobby Electronics

p5.scenemanager's People

Contributors

mveteanu avatar promet99 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

p5.scenemanager's Issues

[Feature Request] support for rectMode(CENTER)

Currently if you have rectMode(CENTER), the button rectangles are drawn correctly relative to the center, however the "hitbox" for the button is still in the normal position, rather than centered

Missing Functions

mouseClicked and windowResized aren't handled by the scene manager, likely among other functions. I've temporarily worked around this in my own project by using mgr.scene.oScene.mouseClicked() to reference the function in the scene object. I'll probably try adding support for these functions later when I've looked into it more.

Incompatibilities with p5.play and it's sprites

There seems to be some major issues when using this lib in conjunction with p5.play and using it's sprites. Scenes get mixed together, collisions start to break, etc. Here's an example of this from a project I'm working on:
exmaple

This lib doesn't seem to currently be able to handle the Group image/sprite structure that p5.play exposes. The only fix for this that I have found is to clear all p5.play groups of all sprites and then re-calling the setup function on the scene before transitioning. However this causes some intense lag as p5.play loads in new assets for the different scenes and creates all the sprites. To get around the lag of loading assets per-scene, you could load in every single asset at the very beginning, but that causes intense lag right from the start, and is a massive waste of resources.

Infinite recursion edgecase

If draw() or a function that calls draw() like windowResized() is called in the setup() function defined in a scene object, setupExecuted will not have yet been set to true and setup will again be called, resulting in runaway recursion. The workaround I'm using is to set setupExecuted to true before calling a function that calls draw(), as demonstrated here:

this.setup = function() {
     this.sceneManager.scene.setupExecuted = true;
     this.windowResized(); //NOTE: Requires setupExecuted override above to prevent infinite recursion
    }

DOM button's event handler cannot be used to change scenes

When using a DOM button, you cannot use mgr.showScene(myScene) inside of the button's event handler to move to another scene in some situations

What's strange is that the event will fire, for example if you add a console.log() to the handler's function it will be called, but the progress function will not work.

If you move to a 'new' scene it will sometimes work, but if you try to re-visit a scene it will fail in my experience.

I believe this has to do with setupExecuted: true withing the function not being reset and thus blocking. Maybe this has something to do with the scoping of the event handlers?

I will follow up with an example of this behavior.

In the meantime, a solution is to create a custom button and render it to the canvas without using an event handler to resolve the scene change:

/*
the one caveat of this is that you should not have overlapping buttons from scene to scene (aka, dont place buttons on the same place on the next scene)

Six parameters for the function:
1: the 'text' for the button : String
2: the scene you want the button to move to : function / name of scene
3: x position : Number
4: y position : Number
5: width : Number
6: height : Number
*/

function specialButton(t,location, x, y, w,h ){
  
  //BEGIN BUTTON CUSTOMIZATION
  //(you'll likey want to clean this up for your use case) ;)
  push() // push/pop just to isolate this incase you want to do other things elsewhere to prevent interference.
    //drop shadow
    fill(0)
    rect(x+2,y+2,w,h)

    //rect
    fill(220)
    rect(x,y,w,h)

    //text
    noFill()
    stroke(0)
  //think about textSize, fonts, etc. if you'd like!
    textAlign(CENTER,CENTER);
    text(t,x,y+h/2,w)
  pop()

  //END BUTTON CUSTOMIZATION
  
  //point rect collision detection
  if (mouseX >= x && mouseX <= x + w && mouseY >= y && mouseY <= y + h) { 
      cursor('pointer') //cursor swap
    if(mouseIsPressed){
      mgr.showScene(location) // load the new scene
    }
  }else{
    cursor(ARROW) //cursor swap
  }
}

[Feature Request] Convert to ESM module

I am having lots of trouble using this in my project. I am not directly importing in browser, so I have to import as additional library. I am having hard time exporting main function for babel/snowpack setup.

Can someone make this an exportable Class?

[Feature Request] Supporting exit() callback on scene change

Really loving this p5 library. Great work!

Something I've been wanting in a few of my projects is an ability to easily execute code when changing away from a scene, something like an exit() to complement enter().

I find it's useful when interacting with the DOM, e.g. in this pattern:

class MyScene {
  enter() {
    select('#html-form').show()
  }

  exit() {
    select('#html-form').hide()
  }
}

Thoughts on if this is a worthwhile feature? If so, happy to send you a pull request.

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.