Automatically scrolling to my player using p5.js, but it does not work

382 views Asked by At

This is what I've tried, but it just doesn't work in p5.js I basically need a line that "renders only the visible portion of the game area on canvas"

Essentially, I need help fixing my function that makes an auto scroller for my game when the player reaches past the co-ordinates 1000x and 300y on the screen...What am I doing wrong?

function ScrollToPlayer(){
  setInterval(function(){
    ScrollTO();
  }, 1);
}
function ScrollTO(){
  if(this.pos.x>1000){
     window.scrollTo(this.pos.x,this.pos.y);
  }
}

https://editor.p5js.org/LttntLark/sketches/JBSg2zIfEf All the code is there. Please read the comments for further explanation on what I need help on.

0

There are 0 answers