Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

76
Visualizações
p5.js multiple canvases and in\out scope

I have a custom class method which is undefined maybe be someone can explain why:

Here is the structure of my sketch:

//global variables

let cx = 0;

.
.
.
let cy = 0;

class Dot(){
  constructor(xps,ypos,col){
   ....
  }
  over(mx,my){
     ....
  }
  //some more functions
}

//canvas def and inst
let inputSketch = function(){
    isktch.setup = function(){
       let inputCanvas = isktch.createCanvas(250,600);
       inputCanvas.position(0,0);
       isktch.background(245,245,240);
    }
    isktch.draw = function(){ 
    ....
    }
    //some other functions
}
let inputSection = new p5(curveSketch,'inputSketch');

//Another canvas
let curveSketch = function(){
    curveSketch.setup = function(){
       let curveCanvas = curveSketch.createCanvas(250,600);
       curveCanvas.position(0,0);
       curveSketch.background(245,245,240);
    }
    curveCanvas.draw = function(){ 
    ....
    }
    //some other functions
}
let curveSection = new p5(curveSketch,'curveSketch');

//some global functions
....
function editPoints(){
    console.log("edit points");
    let p = inputSection.getCurvePoints();
    curveSection.editPointsArr = [];
    for (var i = 0  ; i<p.length ; i++){
       if (p[i].x >=0){
         let dot = new Dot(p[i].x,p[i].y,curveSketch.color(255,77,77));
         dot.over(curveSection.mouseX,curveSection.mouseY);
         dot.update(curveSection.mouseX,curveSection.mouseY);
         dot.display(curveSection);
         curveSection.editPointsArr[i] = dot;
       }   
    }
    curveSection.showPoints = true;
 }

so in this editPoints function it accepts let dot = new Dot(p[i].x,p[i].y,curveSection.color(255,77,77)); but when calling over I get undefined error: TypeError: Cannot read properties of undefined (reading 'over') I tried to enter just numbers over(40,50) - but still get this error What do I do wrong, i'd love to get an advice as I'm stack as hell. Thanks in advance :)

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda