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

169
Visualizações
How do I have two canvas elements on top of each other?
let vehicle;

let path;

function setup() {
  createCanvas(600, 600);
  
  vehicle = new Vehicle(50, 0);


function draw() {
  background(220);

  path.display();

  vehicle.follow(path);
  vehicle.update();
  vehicle.display();
}

var redLight = 'red'
var yellowLight = 'white'
var greenLight = 'white'
var count = 0;

 

function draw() {
  fill("black")
  rect(140, 70, 110, 250)
  fill(redLight)
  ellipse(195, 120, 60, 60)
  fill("white")
  text("RED", 182, 124)
  fill(yellowLight)
  ellipse(195, 200, 60, 60)
  fill("white")
  text("YELLOW", 171, 205)
  fill(greenLight)
  ellipse(195, 280, 60, 60)
  fill("white")
  text("GREEN", 175, 285)
}

Here I have a traffic light and a path and I want them to appear together but I can only make one of them appear so if the traffic light is there it won't show any of the path. How can I change this so that they both appear on the same canvas together.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You are declaring two separate draw() functions, and so the second one you declare replaces the first one. You need to combine your drawing logic into a single function:

let vehicle;

let path;

function setup() {
  createCanvas(600, 600);
  
  vehicle = new Vehicle(50, 0);

  // initialize path ?!
}

function draw() {
  background(220);

  path.display();

  vehicle.follow(path);
  vehicle.update();
  vehicle.display();

  drawTrafficLight();
}

var redLight = 'red'
var yellowLight = 'white'
var greenLight = 'white'
var count = 0;

function drawTrafficLight() {
  fill("black")
  rect(140, 70, 110, 250)
  fill(redLight)
  ellipse(195, 120, 60, 60)
  fill("white")
  text("RED", 182, 124)
  fill(yellowLight)
  ellipse(195, 200, 60, 60)
  fill("white")
  text("YELLOW", 171, 205)
  fill(greenLight)
  ellipse(195, 280, 60, 60)
  fill("white")
  text("GREEN", 175, 285)
}
about 4 years ago · Juan Pablo Isaza Relatório
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