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

266
Visualizações
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 Respostas
Responde à pergunta

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 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