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

423
Visualizações
How can I get a loop in setup() to reset?

I have a for loop in function setup() which I would like to reset and run again when my game resets. The purpose of resetting the loop is to get all the objects in the array back to their start position and colour, or to just create completely new objects.

function setup() {
  createCanvas(550, 550)
  for(let i = 0; i<200; i++) {
    x = random(width)
    y = -50 - 50 * i
    r = random(15,50)
    enemies[i] = new Enemy (x, y, r)
  }
}

I imagine that I won't be able to do this directly since function setup() can only run once, so is there a workaround to get the setup () for loop to reset?

Link to full code here if needed

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

0

Move the relevant code to reset them to another function, perhaps, reset(). Then you can call reset() from setup(), and also call reset() whenever you need to reset them.

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