Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

425
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda