custom event listener - p5.js SceneManager

21 views Asked by At

I am trying to use scene manager in my p5.js application. However, this event is no longer working when I added it to the "gamescene". These lines are on a global level:

function setup() {
  canvas = createCanvas(windowWidth, windowHeight, WEBGL);
  manager = new SceneManager();
  // Preload scenes. Preloading is normally optional
  // ... but needed if showNextScene() is used.
  manager.addScene ( startscene );
  manager.addScene ( gamescene );
  manager.showNextScene();
}
function onPointerlockChange(){
manager.handleEvent("onPointerlockChange");
}
document.addEventListener('pointerlockchange', onPointerlockChange, false);

This is how I added the function to the gamescene:

function gamescene()
{
this.onPointerlockChange = function() {
    if (document.pointerLockElement === canvas.elt ||
      document.mozPointerLockElement === canvas.elt)
      console.log("locked");
    else {
      console.log("unlocked");
      player.pointerLock = false;
    }
    console.log("triggered");
  }
}

Could you please help me out with that? Thank you.

0

There are 0 answers