Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

88
Views
Snake no se mueve correctamente para Pixel Snake Game

¿Por qué mi serpiente no se mueve correctamente? h es la cabeza. Los segmentos siempre parecen colapsar entre sí y se ajustan a las coordenadas principales. Pensé que sería tan simple como quitarlo de atrás y agregarlo al frente, pero supongo que no. ¿Alguna ayuda?

 this.segments.forEach(seg => s.setPixel(seg.x, seg.y, 1)); const h = [...this.segments][0]; hx += this.vX; hy += this.vY; this.segments.unshift(h); this.segments.pop();
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Creo que tal vez el problema es que no estás clonando correctamente la cabeza.

 const h = [...this.segments][0];

Lo anterior asigna el primer elemento en una matriz recién creada que todavía tiene exactamente los mismos objetos dentro. Intenta usar el método Object.assign() :

 this.segments.forEach(seg => s.setPixel(seg.x, seg.y, 1)); const h = Object.assign({}, this.segments[0]); hx += this.vX; hy += this.vY; this.segments.unshift(h); this.segments.pop();

https://www.samanthaming.com/tidbits/70-3-ways-to-clone-objects/#_1-using-spread https://www.samanthaming.com/tidbits/70-3-ways-to- clonar-objetos/#_2-utilizando-objeto-asignar

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!