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

165
Views
Valores del juego de la serpiente rotos

Así que tengo un problema con mi juego de serpientes, está codificado en js y estoy tratando de descubrir cómo hacer un menú donde pueda cambiar los valores, el valor no se registra en la consola y no aparece en el juego.

https://jsfiddle.net/Faxtixe/duq6ba3x/3/

 class Apple { constructor() { let isTouching while (true) { isTouching = false; this.x = Math.floor(Math.random() * canvas.width / snake.size) * snake.size this.y = Math.floor(Math.random() * canvas.height / snake.size) * snake.size for (let i = 0; i < snake.tail.length; i++) { if (this.x == snake.tail[i].x && this.y == snake.tail[i].y) { isTouching = false } } var tb1 = document.getElementById("setInterval").value // fps/Interval var curruntly not working var tb2 = document.getElementById("thisColor").value // color var also curruntly not working console.log(tb1); console.log(tb2); this.size = snake.size this.color = tb2.value // here is the color of the food

y errores de la consola

 window.onload = () => { gameLoop() }
 function gameLoop() { setInterval(show, 1000/tb1.value) // here is our fps value }

Este es el código HTML

 <form> <label for="setInterval">Speed/FPS:</label> <input type="text" id="setInterval" name="setInterval"><br><br> <label for="this.color">Food Color:</label> <input type="text" id="thisColor" name="thisColor"><br><br> <input type="submit" value="Submit"> </form>

Menú

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Como mínimo, debe inicializar la variable tb1.

 const tb1 = document.getElementById("setInterval")

En el formulario, debe tener algún valor inicial, dado que comienza a ejecutar su juego cuando se carga la página y antes de que el usuario tenga la oportunidad de establecer esa variable. Hay otros problemas que deberá resolver para que las cosas funcionen como desea, pero al menos esto lo ayudará a superar el error en su pregunta.

 <input type="text" id="setInterval" name="setInterval" value="50"><br><br>
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!