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

100
Vistas
Trying to throttle just for the jump keypress Javascript HTML5 Canvas Game

Still new at this, have been searching and searching. I see some answers but the code looks a bit different from mine using var and a few others. I found this code to use.

function throttle(cb, delay = 2000) {
  let shouldWait = false

  return (...args) => {
    if (shouldWait) return

    cb (...args)
    shouldWait = true

    setTimeout(() => {
      shouldWait = false
    }, delay)
  }
}

To my understanding that part is correct. I have the basic movement keys. I only want to throttle the jump keypress. Case 87: any help would be greatly appreciated. Trying to avoid players tapping the jump button to fly everywhere. I've tried other alternatives but throttling would solve my problem.

addEventListener('keydown', ({ keyCode }) => {
  if (game.disableUserInput) return
  var lastEnter = null;

  switch (keyCode) {
    case 65:
      console.log('left')
      keys.left.pressed = true
      lastKey = 'left'

      break

    case 83:
      console.log('down')
      break

    case 68:
      console.log('right')
      keys.right.pressed = true
      lastKey = 'right'

      break

    case 87: // W
      console.log('up')    
      if (event.repeat) { return }
      player.velocity.y -= 25           

      break
about 4 years ago · Juan Pablo Isaza
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