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

270
Vistas
Can anybody help me find out why my p5 sketch is crashing every time I run it?

Sadly, I can't put all of the code in this window, but here's the link to the project: https://editor.p5js.org/thing1/sketches/KIsvdFvPt

You can duplicate it to edit it and look at all of the files if you so wish. I'm sorry this is such a vague question, but I've worked so hard on this program and now it feels like it's all been for nothing. Any help is appreciated :) I really appreciate any help you can provide. Many thanks!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Firstly, as mentioned in the comments you're removing from an array whilst iterating through it. This is often needed in game development and the common practice is to iterate through the array backwards:

for (let i = comets.length - 1; i >= 0; i--) {
  // do your removing
}

However, this is only part of the problem. The reason your sketch is freezing, is because you've got the following code in your Comet class:

polygon(this.x,this.y,this.health*2,this.health/5)

So you're setting the radius and npoints of the polygon to values dependent upon the health of the asteroid, you can imagine why it doesn't like it when a negative value is set!

Wrap this code in a simple if:

if (this.health > 0) {
  polygon(this.x, this.y, this.health*2, this.health/5)
}
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